C++ GUI Qt4編程(01)-1.1Hello Qt
阿新 • • 發佈:2017-06-05
運行 執行 整理 解決方法 hello gre int bin pro
1. 根據C++ GUI Qt4編程(第二版)整理
2. 系統:centos7; Qt版本:5.5.1
3. 程序:hello.cpp
#include <QApplication> #include <QLabel> int main(int argc, char *argv[]) { QApplication app(argc, argv); QLabel *label = new QLabel("Hello, Qt!"); label->show(); return app.exec(); }
4. qmake使用別名:$ alias qmake="/opt/Qt/Qt5.5.1/5.5/gcc_64/bin/qmake"
5. 生成與平臺無關的項目文件:$ qmake -project
6. 生成與平臺相關的makefile文件:$ qmake 1.1.pro
7. 構建該程序,生成可執行程序:$ make
8. 運行程序:$ ./1.1
註:1.1是文件夾名稱
問題總結:
1. hello.cpp:1:24: 致命錯誤:QApplication:沒有那個文件或目錄
解決方法:打開1.1.pro文件,添加以下2行:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
C++ GUI Qt4編程(01)-1.1Hello Qt