Qt 編程點滴 初學者必看 (1)
Qt 編程點滴,為大家講解編程那些細節(jié)。通過題目,不難看出,本文講述的就是在編程過程中的點點滴滴,如果你是Qt愛好者,或者是小白,建議你關(guān)注此文章。不多說了,先看看本文吧。
MinGw + CodeBlock + Qt 4.5
類定義后面要加";"
函數(shù)的實現(xiàn)部分,如果定義部分有void,則實現(xiàn)部分不能少;
檢查include文件有無少;
error: request for member `show\\\' in `((MainWindow*)this)->MainWindow::rightform\\\', which is of non-class type `RightForm*\\\'|
"->"與"."問題函數(shù)"()"千萬不能少;
connect中的SLOT里的自定義過程的申明一定要寫在private slots:(或public slots:)下
- Qt ableWidgetItem *newnewItemName = new QtableWidgetItem(tr("姓名"));
- newItemName->setFlags(newItemName->flags() & (~Qt::ItemIsEditable));//網(wǎng)格設(shè)置為只讀
- 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);
if 里面的語句要加括號 if (條件),枚舉類型的定義
- typedef enum{
- nil,
- ready,
- fired,
- exceptional
- }Status;
- QString text = tr("%1 %2").arg(i + 1).arg(files[i]);
- Error:ISO C++ forbids declaration of `NavItem\\\' with no type
如果出現(xiàn)以上的錯誤,其中NavItem是自定義類,則需檢查有沒Include進此類的定義頭文件,并檢查頭文件的#ifndef中的名稱跟其他類有沒重復(fù)(在復(fù)制其它類生成新類時經(jīng)常會出現(xiàn)這樣的錯誤)
\mingw\lib\libmingw32.a(main.o):main.c:(.text+0x104)||undefined reference to `WinMain@16\\\'|
往pro文件按順序加入下面三行:
- -lmingw32 \
- -lSDLmain \
- -lSDL \
sdl庫中文件(sdl.h)里將 #include "SDLMain.h" 注釋掉,否則qDebug(),printf全部無法顯示
有可能使用 #pragma message()造成,方法:不使用#pragma message()
- cannot open output file debug\umpcphonegui.exe: Permission denied
產(chǎn)生此問題是由于文件umpcphonegui.exe受到保護,寫不進去,打開任務(wù)管理器結(jié)束掉此進程就好了
- 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文件;另一原因,虛函數(shù)(或調(diào)用的虛函數(shù))定義后沒有加"=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);
ERROR:undefined reference to `RightGpsForm::RightGpsForm(QWidget*)工程文件(*.pro)文件中的Source沒有加入RightGpsForm類實現(xiàn)的.cpp文件頭部定義有誤,需檢查頭部名稱跟文件名是否一樣;嘗試重編譯
- error: ISO C++ forbids declaration 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-選擇整個工程(左側(cè)第一項)--切到右邊的頁"Search directories"
- 增加"$(#qt4.include)\QtGui\QtCore"
Qt中的目錄用"/"表示
應(yīng)用程序目錄:QCoreApplication::applicationDirPath().append(tr("/world.png"));
QSS:設(shè)置TabWidget中的Tab頁高度
- QTabBar::tab {
- height: 14ex;
- width: 14ex;
- }
- TRACE_SUBSYSF(MYRUNLEVEL,MYMODULENAME,QString(QObject::tr("測試數(shù)據(jù)"))<<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("構(gòu)造函數(shù)創(chuàng)建完畢"))<<10);
- TRACE_SUBSYSF(5,"GUIAPP",tr("構(gòu)造函數(shù)創(chuàng)建完畢")<<10);
- int ret = QMessageBox::question (this, tr("提示"),
tr("確定要刪除文件嗎?"),
- QMessageBox::Yes | QMessageBox::No,
- QMessageBox::No);
引用Dll文件(動態(tài)鏈接"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);
小結(jié):通過Qt 編程點滴 介紹,也給自己提高了編程過程中需要注意的細節(jié)問題,更多內(nèi)容,請看編輯推薦。