#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$
成功
#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$
成功