ref: https://blog.csdn.net/weixin_42837024/article/details/81945656
New Project
- New folder, as the project root directory
- Write main.cpp
main.cpp
#include<QApplication> #include<QWidget> int main(int argc,char ** argv) { QApplication app(argc,argv); QWidget* pWidget = new QWidget(); pWidget->show(); return app.exec(); }
- Into the appropriate folder input
qmake -project
will find a folder created under the platform-independent project file a XXX.pro files (and folders in front of the same name)qmake -project
- Enter the next step
qmake XXX.pro
you have to enter the corresponding pro fileqmake XXX.pro
- Generate some makefile file and debug and release folders ( because handwritten Makefile is more difficult and error-prone, especially the need to write Makefile to several different platforms and compilers combined use qmake, developers create a simple "project" file and run qmake generates the appropriate Makefile.qmake will pay attention to all dependent compiler and platform, developers can be freed only interested in their code )
Compile
If you are using the open-source version of Qt, with the make; if it is a commercial version of Qt, with nmake
- So I enter
make
, will complain, do not worry
Because we use QWidget so to join in the pro file QT += widgets
and then continue to repeat the previous step
- Re-make
- make
Results shown in Figure
Bale
They are packaged under different platforms also not the same. But the principle is similar, the application files are dependent on library put under the same directory
- Windows
- Enter the command windeployqt XXX.exe
- Enigma Virtual Box can then use the files are packaged together
- Linux
1. The resulting compiled executable program (such as: test) copied to an empty directory
2. Use the ldd command to view and export the required libraries
Pack.sh a new file in the directory in step 1, the file follows:
# pack.sh # schips # [email protected] # https://gitee.com/schips/ # Wed 26 Jun 2019 10:38:11 AM HKT ## #!/bin/zsh #你需要发布的程序名称 bin="test_project" # 输出路径 des="./" deplist=$(ldd $bin | awk '{if (match($3,"/")){ printf("%s "),$3 } }') cp $deplist $des
即可