Qt installation and configuration tutorial on Mac

Edited from: https://www.cnblogs.com/GJ-ios/p/15674851.html

This is a Qt installation tutorial that is very suitable for beginners in Qt. Because the company develops desktop applications (Mac and Windows) on the PC side, I choose to install Qt. This time I will record it with this blog and share it with everyone!

First, enter the QT official website
Select the version you need, I chose version 5.14
img
Choose the installation you need, of course, I choose the part outlined for mac

img

Install

1. After the download is complete, double-click to install

img

2. After the verification is successful, the following interface will appear, do not hesitate to next

img

3. Enter the account number. If you don’t have an account, go to the official website to register . You can also register directly in the picture below. I have an account number, just enter it and click next

img

4. Check I have... , click to continue

img

5. Click to continue

img

6. Specify the installation directory and click Continue

img

7. In the next step, you need to select the plug-ins you need. If your computer can’t afford it, it’s okay to select all. After selecting, click Continue, and then you need to wait for a while. After all, you need to download several G plug-ins, be patient wait

img

8. See the following interface, of course I have, and then continue

img

9. Click Install and wait patiently

img

10. After this page appears, click Finish

img

11. After the installation is complete, it will display that you can create a project

img

Configure environment variables

1. Terminal input before configuration: qmake -v

img

2. Still update the ~/.bash_profile file, which does not exist by default. This is basically the same as linux.

Shell code

?

12345 vi ~/.bash_profile``export QTDIR=/Users/guojun/Qt5.14.2/5.14.2/clang_64``export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH ``export PATH=$QTDIR/bin:$PATH ``source ~/.bash_profile

3. Run qmake to print the version information. So far the QT configuration is successful.

img

4、选择Xcode( Xcode can be downloaded from Apple’s developer website (including older versions of Xcode). Once installed, choosing an Xcode installation is done using the xcode-select tool.)

?

123 $ sudo xcode-``select --``switch /Applications/Xcode.app``$ xcode-``select -print-path``/Applications/Xcode.app/Contents/Developer

5、 The xcrun command can then be used to find a particular tool in the toolchain. or show the platform SDK path used when building.

?

12 $ xcrun -sdk macosx -find clang``/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang

?

12 $ xcrun -sdk macosx --show-sdk-path``/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.0.sdk

6. Generate xcode project

?

1 make -spec macx-xcode happy_qt.pro

Or execute it in the directory where the Qt project that needs to be converted is located, refer to :

?

1 qmake -spec macx-xcode happy_qt.pro

7. Packing

When debugging, qt does not copy the dynamic library to the Frameworks of the .app, so we can only run this app locally. If we put it on other computers, we cannot find the lib corresponding to qt. qt provides a packaged command line tool/ usr/local/Cellar/qt@5/5.14.2/bin/macdeployqt

?

12 //cd到app的路径``$ /usr/local/Cellar/qt@5/5.14.2/bin/macdeployqt xxx.app -dmg

8. Other script references

8.1. Use Xcode to open the script

?

12345678910111213 echo macx-xcode start work_path=$(dirname $0)``echo $work_path``cd $work_path cd ../happy_qt qmake -spec macx-xcode ./*.pro open *.xcodeproj echo macx-xcode end

8.2. Packaging script reference

?

| 12345678910 | echo package start``dsymutil *.app/Contents/MacOS/* -o ``"Demo_$(date "``+%Y_%m_%d_%H_%M_%S``").app.dSYM"``macdeployqt *.app -dmg -codesign=``"XXX"``echo package end`` # release || debug 文件夹中的 package脚本``#echo package start``#dsymutil *.app/Contents/MacOS/* -o "Demo_$(date "+%Y_%m_%d_%H_%M_%S").app.dSYM"``#macdeployqt *.app -dmg -codesign="XXX"``#echo package end |
| ----------- | ------------------------------------------------------------ |
| | |

8.3. Copy resource script reference in Xcode

?

12345678910111213141516 echo copy start``pwd``work_path=$(dirname $0)``echo $work_path``cd $work_path``pwd``#rm -rf ../XXX/Debug/DEMO.app/Contents/Frameworks``#cp -R ../bundle/Frameworks ../XXX/Debug/DEMO.app/Contents/``#cp -R ../bundle/Resources ../XXX/Debug/DEMO.app/Contents/ rm -rf ../XXX/Release/DEMO.app/Contents/Frameworks``cp -R ../bundle/Frameworks ../XXX/Release/DEMO.app/Contents/``cp -R ../bundle/Resources ../XXX/Release/DEMO.app/Contents/ echo copy end

Install qt via homebrew

?

123 brew install qt ``//默认是安装最新版本 brew intall qt5 ``//安装qt 5.x版本的

After the installation of this step is completed, the terminal will display the final directory after the installation is completed.

Download and install qtcreator* using homebrew

Guess you like

Origin blog.csdn.net/qq_41854911/article/details/127913541