簡體   English   中英

編譯並運行Qt程序

[英]Compiling and running a Qt program

我是Qt新手,並嘗試編譯並運行我從《 Programming with Qt一書中鍵入的Qt程序:

#include <qapplication.h>
#include <qlabel.h>
int main(int argc, char *argv[])
{
QApplication myapp(argc, argv);
QLabel *mylabel = new QLabel("Hello",0);
mylabel->resize(120,30);
myapp.setMainWidget(mylabel);
mylabel->show();
return myapp.exec();
}

當我這樣做時: Qt command prompt C:\\Qt\\2010.05\\qt>gcc label.cc ,我得到以下信息:

label.cc:1:26: error: qapplication.h: No such file or directory
label.cc:2:20: error: qlabel.h: No such file or directory
label.cc: In function 'int main(int, char**)':
label.cc:5: error: 'QApplication' was not declared in this scope
label.cc:5: error: expected ';' before 'myapp'
label.cc:6: error: 'QLabel' was not declared in this scope
label.cc:6: error: 'mylabel' was not declared in this scope
label.cc:6: error: expected type-specifier before 'QLabel'
label.cc:6: error: expected ';' before 'QLabel'
label.cc:8: error: 'myapp' was not declared in this scope

這是為什么? 我編譯Qt程序的方法正確嗎?

謝謝。

Qmake可以生成一些默認的項目文件,如下所示:

qmake -project
qmake
make

第一行生成項目文件,第二行從項目文件生成makefile並進行構建項目。

要使用Qt系統進行構建,您需要使用元對象編譯器moc。 可能是用戶界面編譯器,uic並定義了包含文件的路徑並鏈接到Qt庫。

通常的方法是使用Qt提供的qmake 您必須為qmake編寫一個項目文件。 這比編寫命令行或makefile容易很多倍。

您缺少包含Qt標頭的包含路徑。

-Ipath_to_qt/include

在您的項目中為專業添加核心,就像這樣:

QT + =核心

QT += widgets添加到您的pro文件中,並將#include <QtWidgets>到您的main.cpp中

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM