1、QT的点点滴滴QT 的点点滴滴 收藏 MinGw + CodeBlock + QT4.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:)下 QTableWidgetItem
2、 *newItemName = new QTableWidgetItem(tr(姓名); newItemName-setFlags(newItemName-flags() & (Qt:ItemIsEditable);/网格设置为只读 tblWidgetMingPian-setItem(0, 0, newItemName); newItemName = new QTableWidgetItem(tr(陈林 & (Qt:ItemIsEditable); tblWidgetMingPian-setItem(0, 1, newItemName);tblWidgetMingPian-verticalHe
3、ader()-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); if 里面的语句要加括号 if (条件) 枚举类型的定义: typedef en
4、um nil, ready, fired, exceptional Status; QString text = tr(%1 %2).arg(i + 1).arg(filesi); Error:ISO C+ forbids declaration of NavItem with no type 如果出现以上的错误,其中NavItem是自定义类,则需检查有没Include进此类的定义头文件,并检查头文件的#ifndef中的名称跟其他类有没重复(在复制其它类生成新类时经常会出现这样的错误)=mingwliblibmingw32.a(main.o):main.c:(.text+0x104)|unde
5、fined reference to WinMain16 |往pro文件按顺序加入下面三行: -lmingw32 -lSDLmain -lSDL sdl库中文件(sdl.h)里将 #include SDLMain.h 注释掉,否则qDebug(),printf全部无法显示 有可能使用 #pragma message()造成,方法:不使用#pragma message()=cannot open output file debugumpcphonegui.exe: Permission denied 产生此问题是由于文件umpcphonegui.exe受到保护,写不进去,打开任务管理器结束掉此进
6、程就好了= pages.h|16|error: expected class-name before token|= Build finished: 1 errors, 0 warnings =|处理方法:没有include进所需的类链接时提示undefind reference to vtable for xxx错误的处理方法: 重新makefile试下或工程文件(.pro)中的HEADERS中没有加入定义该类的.h文件;另一原因,虚函数(或调用的虚函数)定义后没有加=0; int x,y; setupUi(this); this-move(10,60); this-resize(338,5
7、68); x = this-x() + this-frameGeometry().width(); y = this-y() + 20 ; /showMaximized(); rightform = new RightForm; rightform-move(x,y); ERROR:undefined reference to RightGpsForm:RightGpsForm(QWidget*)工程文件(*.pro)文件中的Source没有加入RightGpsForm类实现的.cpp文件头部定义有误,需检查头部名称跟文件名是否一样;尝试重编译 error: ISO C+ forbids de
8、claration of GPSMainWindow with no type| 类的定义GPSMainWindow(gpsmainwindow.h)中的#ifndef MAINWINDOW_H_INCLUDED#define MAINWINDOW_H_INCLUDED头部定义有误,需检查头部名称跟文件名是否一样; #include 时,提示下面的错误: QList: No such file or directory 解决方法:Project-build options-选择整个工程(左侧第一项)-切到右边的页Search directories增加$(#qt4.include)QtGuiQ
9、tCoreQT中的目录用/表示应用程序目录: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/debug/gpsapp.ex
10、e TRACE_SUBSYSF(5,GUIAPP,QString(QObject:tr(构造函数创建完毕)10);TRACE_SUBSYSF(5,GUIAPP,tr(构造函数创建完毕)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 ();/ qDebug() RecentNote
11、ListForm:RecentNoteListForm: *ptr item(0)-data(Qt:UserRole); 删ITEM方法:把把ITEM的数据挂到指针上,先删ITEM,然后再删除指针 如果发生 no such file or directory not find(报QT核心文件错)有可能是project -properties-projects settings中的This is a custom MakeFile没有勾选;检查.pro文件是 INCLUDEPATH += DEPENDPATH+= 有没加入文件所在的目录检查.pro文件是否引入两个版本不同的相同文件名的文件;=枚
12、举类型做为信号的参数,则需对枚举类型进行注册在include中/定义Enumtypedef enum ProgressType, StartType, SuccessType, StopTypeSyncMsgType;/定义结构typedef struct /实际使用中可以多增加些结构成员 SyncMsgType msgtype;SyncMsg;Q_DECLARE_METATYPE(SyncMsg)在应用程序.CPP中/连接之前再注册 qRegisterMetaType(SyncMsg); connect(gpssyncthread, SIGNAL(syncMsgNotify(SyncMsg)
13、, this, SLOT(syncMsgEvent(SyncMsg); =QList listItemDatas; for (QList:iterator it=listItemDatas.begin(); it!=listItemDatas.end() ; +it) (*it)-colName; = error: multiple types in one declaration自定义的类 后面没有;还有一种可能是pro文件中引用了两次单元文件;=expected unqualified-id before int前一句的;误写为,=在Bulid工程时,qmake *.pro死循环,原因:p
14、ro文件里同一文件包含两次;=char *const p ; p所指向的值不能变;char cont *p; P所指向的地址不能变;=error: nameLineEdt was not declared in this scope函数域没有写; (函数域:函数名()ifdef/define重覆=int main(int argc, char *argv) Q_INIT_RESOURCE(qtdam); QApplication app(argc, argv); QSplashScreen *splash = new QSplashScreen; QString path=app.applic
15、ationDirPath(); IDIOMA *lang = new IDIOMA(); lang-setfile_idioma(path+/languages.lng); if (lang-idioma_seleccionado=Espaol) splash-setPixmap(QPixmap(:/images/splash_espagnol.png); else splash-setPixmap(QPixmap(:/images/splash.png); splash-show(); Qt:Alignment topRight = Qt:AlignRight | Qt:AlignTop;
16、splash-showMessage(lang-leer_idioma(1),topRight, Qt:white); MainWindow mainWin; mainWin.show(); splash-finish(&mainWin); delete splash; return app.exec();=函数如果有返回值必须写,否则有造成一些不确定的错误如: QString a()QString str;str = abc;str.append(a();QMessageBox:warning(this, tr(呼叫),str,QMessageBox:Ok);上面的情况,对话框可以出来,但点
17、击对话框中的确定后,程序会死在那;=进行信号连接时,要确保连接参数中的对象已经创建过,否则会报保护错;图片加载不了,有可能是QT库中的插件库没有拷贝;加载路径指令:QCoreApplication:addLibraryPath(QObject:tr(%1%2plugins).arg(QCoreApplication:applicationDirPath().arg(/); qDebug() 插件加载的路径是(QCoreApplication:libraryPaths): QCoreApplication:libraryPaths()endl; 有三个插件加载路径 1,应用程序路径;2,QTDI
18、R环境路径,3,加入的路径; =TRACE_LEVEL=5 TRACE_SUBSYS=DB /d/study/umpcapp/umpcapp-dev-1.0.0/debug/gpsapp.exe = void DragWidget:mousePressEvent(QMouseEvent *event) QLabel *child = static_cast(childAt(event-pos(); if (!child) return; QPixmap pixmap = *child-pixmap(); QByteArray itemData; QDataStream dataStream(&
19、itemData, QIODevice:WriteOnly); dataStream pixmap pos() - child-pos(); = 取得应用程序所在路径,注:结果后面未加/QCoreApplication:applicationDirPath()=*.hpp文件,如果改动,Bulid后对改动后代码不起作用,必须ReBulid才可以;=静态成员变更量aa.hclass AA static char p13;aa.cppchar AA:p13; 如果没在cpp中增加char AA:p13;,则编译时会提示undefined reference to.的错误=b.h接口中引用a.h接口
20、使用时必须加上include a.hinclude b.h否则编译时会出现如果没在cpp中增加char AA:p13;,则编译时会提示=单例模式singleton单元要最先初始化(#include放到最前面)=QWidget类以模式窗体显示: dailPage = new DailForm(0,tel); dailPage-setWindowModality(Qt:ApplicationModal); dailPage-show(); =事件过滤写法:其实可以通过重载QWidget:keyPressEvent()获得本类(假设是窗体)中的几乎所有键盘事件,但焦点在文本框上,就不属于窗体类啦,所
21、以必须采用在窗体类中添加Event Filters:CustomerInfoDialog:CustomerInfoDialog(QWidget *parent) : QDialog(parent) . firstNameEdit-installEventFilter(this); lastNameEdit-installEventFilter(this); cityEdit-installEventFilter(this); phoneNumberEdit-installEventFilter(this);然后在eventFilter中处理相关键盘事件,通过target判断是否是文本框发生的键
22、盘事件bool CustomerInfoDialog:eventFilter(QObject *target, QEvent *event) if (target = firstNameEdit | target = lastNameEdit | target = cityEdit | target = phoneNumberEdit) if (event-type() = QEvent:KeyPress) QKeyEvent *keyEvent = static_cast(event); if (keyEvent-key() = Qt:Key_Space) focusNextChild();
23、 return true; return QDialog:eventFilter(target, event);= 去掉窗体标题栏:setWindowFlags(Qt:FramelessWindowHint);=ld.exe cannot find -lSDL 处理:环境变量path加入D:QtDevelopumpcapppublicSDL-1.2.13bin环境变量path的设置:D:QtDevelopumpcapppublicSTLport-5.1.3bin;D:MinGWbin;D:Qtbin;D:QtDevelopumpcapppublicSDL-1.2.13bin;D:QtDevel
24、opumpcapppublicSDL_mixer-1.2.8bin注:STLport-5.1.3一定要放在MinGW前面,不然会出现QImage: out of memory, returning null image的错误;=如果要用到STLport库,那么在配置.pro文件时,一定要记住把stlport放在其它库的前面,下面的写法是正确的:INCLUDEPATH += . ././public/STLport-5.1.3/stlport #这句一定要放在前面 ././public/SDL-1.2.13/include ././public/common/include ././public/qextserialp
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1