我是新來Qt
,並試圖編譯和運行這個程序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();
}
當我這樣做:C:\Qt\2010.05\qt>gcc label.cc
在Qt command prompt
,我得到以下內容:
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
程序的方式是否正確?
謝謝。
@ user588855你爲什麼不使用[Qt Creator](http://qt.nokia.com/products/developer-tools/)?它會讓你的生活更輕鬆。 – sashoalm 2011-03-28 07:40:32
gcc是c編譯器。你想要g ++。 1)但使用qmake是首選的方式。 2)使用像和 –
2011-03-28 09:09:10
@Ronny這樣的頭文件它取決於你使用的是什麼版本的Qt。 v3 = qapplication.h,v4 = QApplication – koan 2011-03-28 12:33:29