I have been doing QT development under windows/linux, and now I finally have a MAC. I can't wait to try the cross-platform nature of QT and experience the coolness of the MAC interface.
1. Download QT5 for mac
On the graphical interface, click Next.
2. Configure environment variables
Still update the ~/.bash_profile file, which does not exist by default. This is basically the same as linux.
you ~ / .bash_profile export QTDIR=/Users/my/Qt5.7.0/5.7/clang_64 export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH export PATH=$QTDIR/bin:$PATH source ~/.bash_profile
Run qmake to print help information. So far the QT configuration is successful.
lingdeMacBook-Pro:mac lingsun$ qmake -v QMake version 3.0 Using Qt version 5.7.0 in /Users/my/Qt5.7.0/5.7/clang_64/lib
3. Test
Go to the QT Example directory and find any project to compile.
cd /Users/my/Qt5.7.0/Examples/Qt-5.7/charts/areachart #Histogram example qmake #generate makefile make
Execution error:
Project ERROR: Xcode not set up properly. You may need to confirm the license agreement by running /usr/bin/xcodebuild.
The solutions searched by stackoverflow are feasible for personal testing:
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer/ #Specify the xcode path sudo xcodebuild -license #同意license
Compilation still reports the above error, modify default_pre.prf to locate the error line L15.
vi /Users/my/Qt5.7.0/5.7/clang_64/mkspecs/features/mac/default_pre.prf
isEmpty($$list($$system("/usr/bin/xcrun -find xcrun 2>/dev/null")))
Replace with:
isEmpty($$list($$system("/usr/bin/xcrun -find xcodebuild 2>/dev/null")))
Apple thinks that GCC is too large and uses its own clang compiler.
Recompile to generate areachart.app in the current directory.
open -a areachart.app #execute the program
operation result:
4. QtCreator
QtCreator needs to set parameters such as QT version, compiler, etc.
5. Xcode
There is such a high-level IDE on mac as xcode, how can it be abandoned. Xcode projects can be generated with qmake.
lingdeMacBook-Pro:~ lingsun$ qmake -project #生成pro lingdeMacBook-Pro:~ lingsun$ qmake -spec macx-xcode #Generate xcode project lingdeMacBook-Pro:~ lingsun$ open widget.xcodeproj #Open the xcode project
Compilation effect:
6. Precautions
6.1 Chinese garbled characters
The source code file under Windows is encoded in GBK mode, and Chinese characters will appear garbled in the MAC display. Save the source code as UTF-8, and recompile the Chinese to display normally.
6.2 Program Icons
The app icon is set differently under different platforms. The ICON field is displayed under the MAC, and the *.icns picture is specified. The MAC has always been special, and even the pictures are different from other platforms. The icns image can be generated by the iconutil command.
win32{ RC_FILE = ico/online.rc }else{ ICON = ico/app.icns }
6.3 Cross-platform UI
Recompile the QT project under MAC, no code needs to be modified, and everything is compiled normally.
windows:
MAC: