Qt 编程点滴 2

删ITEM方法:

把把ITEM的数据挂到指针上,先删ITEM,然后再删除指针

如果发生 no such file or directory not find(报Qt核心文件错)

有可能是project --properties--projects settings中的"This is a custom MakeFile"没有勾选;

检查.pro文件是   INCLUDEPATH += DEPENDPATH+= 有没加入文件所在的目录

检查.pro文件是否引入两个版本不同的相同文件名的文件;

枚举类型做为信号的参数,则需对枚举类型进行注册

在include中

 
 
  1. //定义Enum  
  2. typedef enum{  
  3.     ProgressType,  
  4.     StartType,  
  5.     SuccessType,  
  6.     StopType  
  7. }  
  8. SyncMsgType;    //定义结构  
  9. typedef struct  //实际使用中可以多增加些结构成员  
  10. {  
  11.     SyncMsgType msgtype;  
  12. }SyncMsg;  
  13. Q_DECLARE_METATYPE(SyncMsg) 

在应用程序.CPP中

 
 
  1. //连接之前再注册  
  2.     qRegisterMetaType("SyncMsg");  
  3.     connect(gpssyncthread, SIGNAL(syncMsgNotify(SyncMsg)),  
  4.             this, SLOT(syncMsgEvent(SyncMsg)));    
  5. QList listItemDatas;  
  6.  for (QList::iterator it=listItemDatas.begin(); it!=listItemDatas.end() ; ++it)  
  7.     {  
  8.         (*it)->colName;  
  9.     }  
  10. error: multiple types in one declaration 

自定义的类 {}后面没有";"

还有一种可能是pro文件中引用了两次单元文件;

expected unqualified-id before "int"前一句的";"误写为","

在Bulid工程时,qmake *.pro死循环,原因:pro文件里同一文件包含两次;

char *const p ; p所指向的值不能变;

char cont *p; P所指向的地址不能变;

error: `nameLineEdt\\\' was not declared in this scope 函数域没有写; (函数域::函数名())ifdef/define重覆

 
 
  1. int main(int argc, char *argv[])  
  2. {  
  3.     Q_INIT_RESOURCE(qtdam);  
  4.       
  5.     QApplication app(argc, argv);  
  6.     QSplashScreen *splash = new QSplashScreen;  
  7.     QString path=app.applicationDirPath();  
  8.     IDIOMA *lang = new IDIOMA();  
  9.     lang->setfile_idioma(path+"/languages.lng");  
  10.     if (lang->idioma_seleccionado=="Español")  
  11.         splash->setPixmap(QPixmap(":/images/splash_espagnol.png"));  
  12.     else  
  13.         splash->setPixmap(QPixmap(":/images/splash.png"));  
  14.     splash->show();  
  15.     Qt::Alignment topRight = Qt::AlignRight | Qt::AlignTop;  
  16.     splash->showMessage(lang->leer_idioma("1"),topRight, Qt::white);  
  17.     MainWindow mainWin;  
  18.     mainWin.show();  
  19.     splash->finish(&mainWin);  
  20.     delete splash;  
  21.     return app.exec();  

函数如果有返回值必须写,否则有造成一些不确定的错误,如:

 
 
  1. QString a()  
  2. {  
  3. }  
  4.  
  5. QString str;  
  6. str = "abc";  
  7. str.append(a());  
  8. QMessageBox::warning(this, tr("呼叫"),str,QMessageBox::Ok); 

上面的情况,对话框可以出来,但点击对话框中的"确定"后,程序会死在那;

进行信号连接时,要确保连接参数中的对象已经创建过,否则会报保护错;

图片加载不了,有可能是Qt库中的插件库没有拷贝;

加载路径指令:

 
 
  1. QCoreApplication::addLibraryPath(QObject::tr("%1%2plugins").arg(QCoreApplication::applicationDirPath()).arg("/")); 

qDebug() << "插件加载的路径是(QCoreApplication::libraryPaths):" << QCoreApplication::libraryPaths()<        

有三个插件加载路径 1,应用程序路径;2,QTDIR环境路径,3,加入的路径;     

 
 
  1. TRACE_LEVEL=5 TRACE_SUBSYS=DB /d/study/umpcapp/umpcapp-dev-1.0.0/debug/gpsapp.exe   
  2.  
  3.  void DragWidget::mousePressEvent(QMouseEvent *event)  
  4.  {  
  5.      QLabel *child = static_cast(childAt(event->pos()));  
  6.      if (!child)  
  7.          return;  
  8.  
  9.      QPixmap pixmap = *child->pixmap();  
  10.  
  11.      QByteArray itemData;  
  12.      QDataStream dataStream(&itemData, QIODevice::WriteOnly);  
  13.      dataStream << pixmap << QPoint(event->pos() - child->pos()); 


取得应用程序所在路径,注:结果后面未加"/"

 
 
  1. QCoreApplication::applicationDirPath() 

*.hpp文件,如果改动,Bulid后对改动后代码不起作用,必须ReBulid才可以;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值