Qt 编程点滴1

MinGw + CodeBlock + Qt 4.5

类定义后面要加";"

函数的实现部分,如果定义部分有void,则实现部分不能少;

检查include文件有无少;

error: request for member `show\\\' in `((MainWindow*)this)->MainWindow::rightform\\\', which is of non-class type `RightForm*\\\'|
"->"与"."问题函数"()"千万不能少;

connect中的SLOT里的自定义过程的申明一定要写在private slots:(或public slots:)下


  1. Qt ableWidgetItem *newnewItemName = new QtableWidgetItem(tr("姓名"));  
  2. newItemName->setFlags(newItemName->flags() & (~Qt::ItemIsEditable));//网格设置为只读  
  3. tblWidgetMingPian->setItem(0, 0, newItemName);  
  4. newnewItemName = new QtableWidgetItem(tr("陈林 & (~Qt::ItemIsEditable));  
  5. tblWidgetMingPian->setItem(0, 1, newItemName);  
  6. idgetMingPian->verticalHeader()->hide();  
  7. tblWidgetMingPian->horizontalHeader()->hide();  
  8. tblWidgetMingPian->setRowHeight(0,25);  
  9. tblWidgetMingPian->setRowHeight(1,25);  
  10.  
  11.  
  12.     tblWidgetMingPian->setRowCount(2);connsql.h  
  13. tblWidgetMingPian->setColumnWidth(0,60);  
  14. tblWidgetMingPian->setColumnWidth(1,100); 


    
if 里面的语句要加括号 if (条件),枚举类型的定义


  1. typedef enum{  
  2.      nil,  
  3.      ready,  
  4.      fired,  
  5.      exceptional  
  6.  }Status; 

  1. QString text = tr("%1 %2").arg(i + 1).arg(files[i]);   
  2. Error:ISO C++ forbids declaration of `NavItem\\\' with no type   

如果出现以上的错误,其中NavItem是自定义类,则需检查有没Include进此类的定义头文件,并检查头文件的#ifndef中的名称跟其他类有没重复(在复制其它类生成新类时经常会出现这样的错误)

\mingw\lib\libmingw32.a(main.o):main.c:(.text+0x104)||undefined reference to `WinMain@16\\\'|

往pro文件按顺序加入下面三行:


  1. -lmingw32 \  
  2. -lSDLmain \  
  3. -lSDL \ 

sdl库中文件(sdl.h)里将 #include "SDLMain.h" 注释掉,否则qDebug(),printf全部无法显示

有可能使用 #pragma message()造成,方法:不使用#pragma message()


  1. cannot open output file debug\umpcphonegui.exe: Permission denied 

产生此问题是由于文件umpcphonegui.exe受到保护,写不进去,打开任务管理器结束掉此进程就好了


  1. pages.h|16|error: expected class-name before \\\'{\\\' token|  
  2. ||=== Build finished: 1 errors, 0 warnings ===| 

处理方法:没有include进所需的类

链接时提示""undefind reference to \\\'vtable for xxx\\\'错误的处理方法: 重新makefile试下或工程文件(.pro)中的HEADERS中没有加入定义该类的.h文件;另一原因,虚函数(或调用的虚函数)定义后没有加"=0";


  1. int x,y;  
  2. setupUi(this);  
  3. this->move(10,60);  
  4. this->resize(338,568);  
  5. x = this->x() + this->frameGeometry().width();  
  6. y = this->y() + 20 ;  
  7. //showMaximized();  
  8. rightform = new RightForm;  
  9. rightform->move(x,y); 

ERROR:undefined reference to `RightGpsForm::RightGpsForm(QWidget*)工程文件(*.pro)文件中的Source没有加入RightGpsForm类实现的.cpp文件头部定义有误,需检查头部名称跟文件名是否一样;尝试重编译


  1. error: ISO C++ forbids declaration of `GPSMainWindow\\\' with no type|     

类的定义GPSMainWindow(gpsmainwindow.h)中的


  1. #ifndef MAINWINDOW_H_INCLUDED  
  2. #define MAINWINDOW_H_INCLUDED 

头部定义有误,需检查头部名称跟文件名是否一样;

#include 时,提示下面的错误:   


  1. QList: No such file or directory    

解决方法:

Project-build options-选择整个工程(左侧第一项)--切到右边的页"Search directories"


  1. 增加"$(#qt4.include)\QtGui\QtCore" 

Qt中的目录用"/"表示

应用程序目录:QCoreApplication::applicationDirPath().append(tr("/world.png"));

QSS:设置TabWidget中的Tab页高度


  1. QTabBar::tab {  
  2.   height: 14ex;  
  3.   width: 14ex;  
  4. }  
  5. TRACE_SUBSYSF(MYRUNLEVEL,MYMODULENAME,QString(QObject::tr("测试数据"))<<10);  
  6. TRACE_LEVEL=5 TRACE_SUBSYS=MAIN /d/study/umpcapp/umpcapp-dev-1.0.0/gpsapp/deb  
  7. ug/gpsapp.exe   
  8.  
  9. TRACE_SUBSYSF(5,"GUIAPP",QString(QObject::tr("构造函数创建完毕"))<<10);  
  10. TRACE_SUBSYSF(5,"GUIAPP",tr("构造函数创建完毕")<<10);  
  11. int ret = QMessageBox::question (this, tr("提示"), 

tr("确定要删除文件吗?"),


  1. QMessageBox::Yes | QMessageBox::No,  
  2. QMessageBox::No); 

引用Dll文件(动态链接"qextserialport.dll")时,需在pro里加下面的语句, -l+dll文件名   


  1. LIBS += -lqextserialport       
  2.  
  3. //  
  4. //    listWidget->addItem("a");  
  5. //    listWidget->addItem("b");  
  6. //    QVariant var;  
  7. //    var.setValue (new int(789098));  
  8. //  
  9. //    listWidget->item(0)->setData(Qt::UserRole,var);  
  10. //  
  11. //    int* ptr = listWidget->item(0)->data(Qt::UserRole).value < int>();  
  12. //    qDebug()<< "RecentNoteListForm::RecentNoteListForm:" << *ptr << endl;  
  13. //    delete ptr;  
  14. //    delete &listWidget->item(0)->data(Qt::UserRole);  

你可能感兴趣的:(qt)