sudo apt-get upadte
sudo apt-get install qt4-dev-tools
sudo apt-get install qtcreator
sudo apt-get install qt4-doc
sudo apt-get install qt4-qtconfig
sudo apt-get install qt-demos
编译指令
qmake -project
qmake
make
实现Ubuntu20,04 与Windows之间的复制粘贴
安装open-vm-tools-desktop:sudo apt-get install open-vm-tools-desktop
sudo apt-get install open-vm-tools-desktop /
重启Ubuntu系统:reboot
sudo reboot
#include<QApplication>
#include<QLabel>
int main(int argc,char** argv)
{QApplication app(argc, argv);QLabel label("hello world");label.show();app.exec();return 0;
}
The error you’re encountering indicates that the compiler can’t find the QApplication
header file, which is part of the Qt framework. This is likely because the necessary Qt development packages are not installed, or the include paths for Qt are not correctly specified.
Here’s how to troubleshoot and resolve this issue:
1. Ensure Qt Development Packages are Installed
On a Debian-based system (like Ubuntu), you can install the necessary Qt development packages with the following command:
sudo apt-get install qt5-default libqt5gui5 libqt5core5a libqt5widgets5
2. Verify Include Paths
Make sure that the include paths specified with -I
flags in your command line correctly point to the Qt headers. The paths you used seem to be pointing to the correct directories, but double-check that the headers are indeed located there:
/usr/include/x86_64-linux-gnu/qt5
/usr/include/x86_64-linux-gnu/qt5/QtGui
/usr/include/x86_64-linux-gnu/qt5/QtCore
Specifically, make sure that the QApplication
header exists at the expected path, which should be something like:
/usr/include/x86_64-linux-gnu/qt5/QtWidgets/QApplication
Note that QApplication
is part of the QtWidgets
module, so you’ll need to include that in your include paths if it isn’t already.
3. Include the Correct Module
Since QApplication
is part of the QtWidgets
module, you need to ensure that the include path for QtWidgets
is specified, and you should explicitly include QtWidgets
in your code:
#include <QApplication>
Also, ensure the include path for QtWidgets
is set up correctly:
-I/usr/include/x86_64-linux-gnu/qt5/QtWidgets
4. Recompile
After verifying the above steps, try recompiling your code:
g++ -c -pipe -O2 -Wall -Wextra -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_WIDGETS_LIB -I/usr/include/x86_64-linux-gnu/qt5 -I/usr/include/x86_64-linux-gnu/qt5/QtGui -I/usr/include/x86_64-linux-gnu/qt5/QtCore -I/usr/include/x86_64-linux-gnu/qt5/QtWidgets -I. -o day1.o day1/day1.cpp
This should resolve the QApplication
not found error.