比较简单的办法如下:
QWidget *spacer = new QWidget(this);
spacer->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
toolBar->addWidget(spacer);
但是如何右对齐的是一个自定义的复合控件,则无能为力,比如一个编辑框和一个搜索按钮
这种情况下可以使用QLayout和QSpacerItem即可完成,如下:
QWidget* searchWidget = new QWidget(this);
mToolbar->addWidget(searchWidget);
QHBoxLayout* searchLayout = new QHBoxLayout(searchWidget);
QSpacerItem* spacer = new QSpacerItem(40,20,QSizePolicy::Expanding,QSizePolicy::Minimum);
searchLayout->addItem(spacer);
mSearchButtonWidget = new QPushButton(tr("搜索"),searchWidget);
mSearchEditWidget = new QLineEdit(searchWidget);
mSearchEditWidget->setMaximumWidth(120);
searchLayout->addWidget(mSearchEditWidget);
searchLayout->addWidget(mSearchButtonWidget);
原因是QToolBar本身就是一个QWidget
脚本如下:
from bs4 import BeautifulSoup
def list_get(file):
soup = BeautifulSoup(open(file))
alist = soup.find_all('a',class_ = 'link')
list = []
for i in alist:
list.append(i.get('href'));
#for i in list:
# print(i)
return list
if __name__=="__main__":
list_get('List.htm')
list_get函数返回的是list字符串对象
其c语言调用的代码如下:
#include <stdio.h>
#include <stdlib.h>
#include <Python.h>
char* GDALPythonObjectToCStr(PyObject* pyObject);
int main(int argc, char *argv[])
{
Py_Initialize();
if(!Py_IsInitialized())
{
return -1;
}
PyRun_SimpleString("import sys");
PyRun_SimpleString("sys.path.append('./script')");
PyObject* pModule;
PyObject* pDict;
PyObject* pFunc;
pModule = PyImport_ImportModule("list");
if(!pModule)
{
printf("can't find list.py");
system("PAUSE");
getchar();
return -1;
}
pDict = PyModule_GetDict(pModule);
if(!pDict)
{
return -1;
}
pFunc = PyDict_GetItemString(pDict,"list_get");
if(!pFunc || !PyCallable_Check(pFunc))
{
printf("can't find function [list_get]");
getchar();
return -1;
}
PyObject* args = PyTuple_New(1);
PyTuple_SetItem(args,0,Py_BuildValue("s","List.htm"));
PyObject* value = PyObject_CallObject(pFunc,args);
int ret = PySequence_Check(value);
printf("check:%d\n",ret);
int length = PySequence_Size(value);
printf("length:%d\n",length);
int i = 0;
for(;i<length;i++)
{
PyObject* obj = PySequence_GetItem(value,i);
//char* str = PyBytes_AS_STRING(obj);
char* str = GDALPythonObjectToCStr(obj);
printf("link:%s\n",str);
free(str);
}
Py_DECREF(args);
Py_DECREF(pModule);
Py_Finalize();
system("PAUSE");
return 0;
}
/* Return a NULL terminated c String from a PyObject */
/* Result must be freed with GDALPythonFreeCStr */
char* GDALPythonObjectToCStr(PyObject* pyObject)
{
#if PY_VERSION_HEX >= 0x03000000
if(PyUnicode_Check(pyObject))
{
char *pszStr;
char *pszNewStr;
Py_ssize_t nLen;
PyObject* pyUTF8Str = PyUnicode_AsUTF8String(pyObject);
PyBytes_AsStringAndSize(pyUTF8Str,&pszStr,&nLen);
pszNewStr = (char*)malloc(nLen+1);
memcpy(pszNewStr,pszStr,nLen+1);
Py_XDECREF(pyUTF8Str);
return pszNewStr;
}
else if(PyBytes_Check(pyObject))
{
char *pszStr;
char *pszNewStr;
Py_ssize_t nLen;
PyBytes_AsStringAndSize(pyObject,&pszStr,&nLen);
pszNewStr = (char*)malloc(nLen+1);
memcpy(pszNewStr,pszStr,nLen+1);
return pszNewStr;
}
else
{
char *pszStr = (char*)malloc(1);
pszStr[0] = '\0';
return pszStr;
}
#else
return PyString_AsString(pyObject);
#endif
}
不得不承认,有时候使用python比c++方便很多,
就拿解析html来说,使用 Beautiful Soup 就比使用libtidy方便很多 - 当然也有可能是
Beautiful Soup封装的很厉害吧
使用Beautiful Soup的一个例子如下:
from bs4 import BeautifulSoup
soup = BeautifulSoup(open('List.htm'))
for a in soup.find_all('a',class_ = 'link'):
print (a.get('href'))
目的是找出html中class属性为link的a节点对应的href属性字符串
如果是使用c++ libtidy的话
对应的代码如下:
Bool TIDY_CALL tidyFilterCb(TidyDoc tdoc,TidyReportLevel lvl,uint line,uint col,ctmbstr mssg)
{
return no;
}
void extractContent(TidyNode node,TidyDoc doc);
void parseContent(TidyNode node,TidyDoc doc)
{
TidyNode child;
for(child = tidyGetChild(node);child;child = tidyGetNext(child))
{
if(tidyNodeIsA(child))
extractContent(child,doc);
else
parseContent(child,doc);
}
}
void extractContent(TidyNode node,TidyDoc doc)
{
if(yes == tidyNodeIsA(node))
{
TidyAttr cls = tidyAttrGetCLASS(node);
if(cls != NULL)
{
char* value = (char*)tidyAttrValue(cls);
if(!strcmp(value,"link"))
{
TidyAttr href = tidyAttrGetHREF(node);
if(href != NULL)
{
char* link = (char*)tidyAttrValue(href);
printf("link:%s\n",link);
return;
}
}
}
}
parseContent(node,doc);
}
void tidyParseHtml(char* file)
{
TidyDoc doc = tidyCreate();
tidySetReportFilter(doc,tidyFilterCb);
tidyParseFile(doc,file);
TidyNode body = tidyGetBody(doc);
TidyNode child;
for(child = tidyGetChild(body);child;child = tidyGetNext(child))
{
parseContent(child,doc);
}
tidyRelease(doc);
}
还是很啰嗦的
当然下面的python代码也能完成任务:
from bs4 import BeautifulSoup
soup = BeautifulSoup(open('List.htm'))
list = soup.select('a[class="link"]')
for a in list:
if a.has_attr('href'):
print (a.get('href'))
如果想分析网页我觉得BeatifulSoup绝对是一个利器
链接:
http://www.crummy.com/software/BeautifulSoup/bs4/doc/
gaudio是一个基于C/C++混合编程的跨平台音频库,当前支持windows32/64操作系统和linux32位操作系统
当前性能:
1.最大支持音源同时播放的格式-8
2.单音源最大挂载的音效个数-8
3.全局最大可挂载的音效个数-8
4.当前支持语言C/C++/C#
5.当前支持的OS Win32/Win64/Linux32
6. 当前支持的音效-Fade in,Fade Out,Bassboost,Speed Changer,Echo,3D Effect, Doppler, Phaser, Channel Merget, Channel Swap, Fft, Distortion, Foldback Distortion, Modulator, AutoWah 等
7.当前支持的解码格式 - WAV, AU, AIFF, OGG, MOD,IT,XM,S3M,WV,MPC,WV,TTA,MP3,MIDI,FLAC
8.支持的编码格式 - WAV,AU,AIFF,OGG,MP2,MP3,FLAC,AAC,WV,VOC,CAF
9.支持的音频加载模式 - 文件加载,内存加载,虚拟文件加载
10.支持PAN,环绕音,全音量,音源音量设置
下一步计划:
1.DEPHI绑定
2.MAC OS支持
3.Flanger,Chorus音效
4.TAK,AAC格式
5.故障处理
远景:
1.支持所有平台和手持设备
2.支持常见的所有音频格式
3.支持常见的所有音效
4.提高最易用最方便的API接口
一个使用的小例子:
/*
GAudio 2.1.0.1, (C)2013 by Eric Du(E)
This program is a part of the GAudio SDK.
Use GAudio's echo effect
*/
#include <stdlib.h>
#include <conio.h>
#include <stdio.h>
#include "gaudio.h"
int main(int argc,char* argv[])
{
printf("echo created by D.Eric\n");
#if(defined(WIN32) || defined(WIN64))
gaudio_init("addons");
#else
gaudio_init("/usr/local/lib/gaudio/");
#endif
const char* filename = "..\\media\\hurnscald.ogg";
gsource* source = gaudio_source_create_from_file(filename,FALSE);
if(source == NULL)
{
printf("load file:%s error!\n",filename);
printf("bad source.\nerror code:%d.\n",gaudio_error_get());
gaudio_deinit();
return -1;
}
gaudio_source_set_int32(source,AUDIO_ENUM_LOOP,FALSE);
printf("play filename:%s\n",filename);
geffect* effect = gaudio_effect_create(AUDIO_EFFECT_ECHO,0);
if(!effect)
{
printf("not support echo effect\n");
gaudio_source_destroy(source);
gaudio_deinit();
return -1;
}
gaudio_effect_set_float(effect,AUDIO_EFFECT_ECHO_DELAY,1.0f);
gaudio_effect_set_float(effect,AUDIO_EFFECT_ECHO_DECAY,0.6f);
gaudio_effect_bind(effect,0);
gaudio_source_play(source,FALSE);
printf("\nplaying, press any key to quit.\n");
getch();
gaudio_effect_unbind(effect);
gaudio_effect_destroy(effect);
gaudio_source_stop(source);
gaudio_source_destroy(source);
gaudio_deinit();
system("PAUSE");
return EXIT_SUCCESS;
}
这个代表了我当前对音频这块的了解程度
下载在这里:
download欢迎提意见啊.
摘要: 1.Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->/* === Shared === */QStackedWidget, QLabel, QPushButton, QRadioBu...
阅读全文
发现一个问题imageView.startAnimation启动控件动画以后
由于一些原因需要设置控件为GONE状态,也就是imageView.s
etVisibility(View.GONE);
之后发现控件处于GONE状态,但是控件还是可见的
上网查了下发现要清空动画,也就是imageView.clearAnimation
其实我觉得如果调用setVisibility(View.GONE)之后无论当前有无动画都应该消失
设置为GONE状态后控件状态出现异常
按照当前情况要隐藏控件需要先调用cleanAnimation,之后call setVisibility
所以有空想想android API也并非十全十美.
各位觉得呢?
截图如下:
2013年10月6日星期日
代码见附件:
/Files/gaimor/GPlayer.zip
摘要: 之前写了一个dll,具体在这里http://www.cppblog.com/gaimor/anarchive/2013/07/11/201711.html现在想增加一个c#绑定,上网搜了下很简单就实现了实现后的cs代码如下(当前只实现了一部分):Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.Co...
阅读全文
1. -static-libstdc++ for libstdc
++-6.dll2. -static-libgcc for libgcc_s_dw2-1.dll
直接上代码:
#include <stdio.h>
#include <ao/ao.h>
#include "mpg123.h"
int main(int argc, char *argv[])
{
ao_initialize();
mpg123_handle *mpg123 ;
int iMpg123_error;
if(MPG123_OK != (iMpg123_error = mpg123_init()))
{
printf("failed to init mpg123\n");
return -1;
}
mpg123 = mpg123_new(mpg123_decoders()[0], &iMpg123_error);
if(MPG123_OK != (iMpg123_error = mpg123_open(mpg123,argv[1])))
{
fprintf(stderr,"error in open mp3 file\n");
return -1;
}
int rate,channel,encoding;
mpg123_getformat(mpg123,&rate,&channel,&encoding);
int default_driver = ao_default_driver_id();
ao_sample_format format;
memset(&format,0,sizeof(format));
format.bits = 16;
format.channels = channel;
format.rate = rate;
format.byte_format = AO_FMT_LITTLE;
ao_device *device;
device = ao_open_live(default_driver,&format,NULL);
if(device == NULL)
{
fprintf(stderr,"error opening device.\n");
return 1;
}
short buffer[4096];
int read = 0;
while(1)
{
mpg123_read(mpg123,buffer,4096,&read);
if(read == 0)
break;
ao_play(device,buffer,read);
}
mpg123_close(mpg123);
ao_close(device);
ao_shutdown();
return 0;
}