Qt 编程点滴,为大家讲解编程那些细节。通过题目,不难看出,本文讲述的就是在编程过程中的点点滴滴,如果你是Qt爱好者,或者是小白,建议你关注此文章。不多说了,先看看本文吧。
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:)下
复制
Qt ableWidgetItem *newnewItemName = new QtableWidgetItem(tr("姓名")); newItemName->setFlags(newItemName->flags() & (~Qt::ItemIsEditable));//网格设置为只读 tblWidgetMingPian->setItem(0, 0, newItemName); newnewItemName = new QtableWidgetItem(tr("陈林 & (~Qt::ItemIsEditable)); tblWidgetMingPian->setItem(0, 1, newItemName); idgetMingPian->verticalHeader()->hide(); tblWidgetMingPian->horizontalHeader()->hide(); tblWidgetMingPian->setRowHeight(0,25); tblWidgetMingPian->setRowHeight(1,25); tblWidgetMingPian->setRowCount(2);connsql.h tblWidgetMingPian->setColumnWidth(0,60); tblWidgetMingPian->setColumnWidth(1,100);
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
if 里面的语句要加括号 if (条件),枚举类型的定义
复制
typedef enum{ nil, ready, fired, exceptional }Status;
1.
2.
3.
4.
5.
6.
复制
QString text = tr("%1 %2").arg(i + 1).arg(files[i]); Error:ISO C++ forbids declaration of `NavItem\\\' with no type
1.
2.
如果出现以上的错误,其中NavItem是自定义类,则需检查有没Include进此类的定义头文件,并检查头文件的#ifndef中的名称跟其他类有没重复(在复制其它类生成新类时经常会出现这样的错误)
\mingw\lib\libmingw32.a(main.o):main.c:(.text+0x104)||undefined reference to `WinMain@16\\\'|
往pro文件按顺序加入下面三行:
复制
-lmingw32 \ -lSDLmain \ -lSDL \
1.
2.
3.
sdl库中文件(sdl.h)里将 #include "SDLMain.h" 注释掉,否则qDebug(),printf全部无法显示
有可能使用 #pragma message()造成,方法:不使用#pragma message()
复制
cannot open output file debug\umpcphonegui.exe: Permission denied
1.
产生此问题是由于文件umpcphonegui.exe受到保护,写不进去,打开任务管理器结束掉此进程就好了
复制
pages.h|16|error: expected class-name before \\\'{\\\' token| ||=== Build finished: 1 errors, 0 warnings ===|
1.
2.
处理方法:没有include进所需的类
链接时提示""undefind reference to \\\'vtable for xxx\\\'错误的处理方法: 重新makefile试下或工程文件(.pro)中的HEADERS中没有加入定义该类的.h文件;另一原因,虚函数(或调用的虚函数)定义后没有加"=0";
复制
int x,y; setupUi(this); this->move(10,60); this->resize(338,568); x = this->x() + this->frameGeometry().width(); y = this->y() + 20 ; //showMaximized(); rightform = new RightForm; rightform->move(x,y);
1.
2.
3.
4.
5.
6.
7.
8.
9.
ERROR:undefined reference to `RightGpsForm::RightGpsForm(QWidget*)工程文件(*.pro)文件中的Source没有加入RightGpsForm类实现的.cpp文件头部定义有误,需检查头部名称跟文件名是否一样;尝试重编译
复制
error: ISO C++ forbids declaration of `GPSMainWindow\\\' with no type|
1.
类的定义GPSMainWindow(gpsmainwindow.h)中的
复制
#ifndef MAINWINDOW_H_INCLUDED #define MAINWINDOW_H_INCLUDED
1.
2.
头部定义有误,需检查头部名称跟文件名是否一样;
#include 时,提示下面的错误:
复制
QList: No such file or directory
1.
解决方法:
Project-build options-选择整个工程(左侧第一项)--切到右边的页"Search directories"
复制
增加"$(#qt4.include)\QtGui\QtCore"
1.
Qt中的目录用"/"表示
应用程序目录:QCoreApplication::applicationDirPath().append(tr("/world.png"));
QSS:设置TabWidget中的Tab页高度
复制
QTabBar::tab { height: 14ex; width: 14ex; } TRACE_SUBSYSF(MYRUNLEVEL,MYMODULENAME,QString(QObject::tr("测试数据"))<<10); TRACE_LEVEL=5 TRACE_SUBSYS=MAIN /d/study/umpcapp/umpcapp-dev-1.0.0/gpsapp/deb ug/gpsapp.exe TRACE_SUBSYSF(5,"GUIAPP",QString(QObject::tr("构造函数创建完毕"))<<10); TRACE_SUBSYSF(5,"GUIAPP",tr("构造函数创建完毕")<<10); int ret = QMessageBox::question (this, tr("提示"),
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
tr("确定要删除文件吗?"),
复制
QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
1.
2.
引用Dll文件(动态链接"qextserialport.dll")时,需在pro里加下面的语句, -l+dll文件名
复制
LIBS += -lqextserialport // // listWidget->addItem("a"); // listWidget->addItem("b"); // QVariant var; // var.setValue (new int(789098)); // // listWidget->item(0)->setData(Qt::UserRole,var); // // int* ptr = listWidget->item(0)->data(Qt::UserRole).value < int* >(); // qDebug()<< "RecentNoteListForm::RecentNoteListForm:" << *ptr << endl; // delete ptr; // delete &listWidget->item(0)->data(Qt::UserRole);
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
小结:通过Qt 编程点滴 介绍,也给自己提高了编程过程中需要注意的细节问题,更多内容,请看编辑推荐。