QT编译出现fatal error: QApplication: No such file or directory

 #include <QApplication>
 #include <QLabel>
 
  int main(int argc, char **argv)
   {
          QApplication app(argc, argv);
         QLabel *label = new QLabel("hello world");
          label->show();
         return app.exec();
  }

yijun@ubuntu:~/qt/hello$ qmake -project
yijun@ubuntu:~/qt/hello$ qmake hello.pro
运行出错
yijun@ubuntu:~/qt/hello$ make
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -fPIE -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I../../Qt5.1.1/5.1.1/gcc/mkspecs/linux-g++ -I. -I. -I../../Qt5.1.1/5.1.1/gcc/include -I../../Qt5.1.1/5.1.1/gcc/include/QtGui -I../../Qt5.1.1/5.1.1/gcc/include/QtCore -I. -o main.o main.cpp
main.cpp:1:24: fatal error: QApplication: No such file or directory
compilation terminated.
yijun@ubuntu:~/qt/hello$


因为Qt5里不再用QtGui模块,而是使用QtWidgets模块,
所以在.pro里加上
在hello.pro文件中添加
 QT += core gui widgets

yijun@ubuntu:~/qt/hello$ make
/home/yijun/Qt5.1.1/5.1.1/gcc/bin/qmake -o Makefile hello.pro
g++ -Wl,-O1 -Wl,-rpath,/home/yijun/Qt5.1.1/5.1.1/gcc -Wl,-rpath,/home/yijun/Qt5.1.1/5.1.1/gcc/lib -o hello main.o   -L/home/yijun/Qt5.1.1/5.1.1/gcc/lib -lQt5Widgets -lQt5Gui -lQt5Core -lGL -lpthread
/usr/bin/ld: cannot find -lGL
collect2: ld returned 1 exit status
make: *** [hello] Error 1
yijun@ubuntu:~/qt/hello$
解决办法:
sudo apt-get install libglu1-mesa-dev -y
装完以后(装的过程比较漫长,而且网速也不给力,装完就重启了ubuntu)
yijun@ubuntu:~/qt/hello$ make
g++ -Wl,-O1 -Wl,-rpath,/home/yijun/Qt5.1.1/5.1.1/gcc -Wl,-rpath,/home/yijun/Qt5.1.1/5.1.1/gcc/lib -o hello main.o   -L/home/yijun/Qt5.1.1/5.1.1/gcc/lib -lQt5Widgets -lQt5Gui -lQt5Core -lGL -lpthread
yijun@ubuntu:~/qt/hello$
成功
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值