QT中運行程式時出現錯誤“ QApplication: No such file or directory"

來源:互聯網
上載者:User

標籤:c++   qt   

在根目錄下建立 一個檔案夾,名稱為hello,在該檔案夾下建立一個hello.cpp檔案,內容如下:

#include <QApplication>#include <QLabel>int main(int argc, char **argv){ QApplication  a(argc, argv); QLabel mylabel("Hello the World"); mylabel.show(); return a.exec();}

在該檔案下運行以下命令:

qmake -project

該命令產生一個hello.pro工程檔案

qmake

該命令產生一個Makefile檔案

make

該命令用來產生目標檔案:hello,hello.o檔案

不過在此過程中遇到一個錯誤:


g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -o hello.o hello.cpp
hello.cpp:1:24: fatal error: QApplication: No such file or directory
 #include <QApplication>
                        ^
compilation terminated.
make: *** [hello.o] Error 1

原因:沒有安裝QT4的開發包

解決方案:

把開發封裝上,在Ubuntu下使用如下命令:sudo apt-get install libqt4-dev

此時再運行make命令即可產生hello,hello.o檔案,

在該目錄下運行./hello命令,即可運行產生的程式。



QT中運行程式時出現錯誤“ QApplication: No such file or directory"

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.