Monday, February 7, 2011

Qt Creator/qmake compiling issues on Mac and Windows

Qt Creator is the best tool for you to create/maintain cross platform (Mac, Windows, Linux) project files. You can use Qt Creator project file (*.pro) to handle the platform dependent files as well. In addition, there are also slight difference between Windows and Mac when you use qmake.

1. Add platform dependent configures in pro file.

Please refer to the code below:
mac {
ICON = images/app.icns
LIBS += -framework Cocoa
win32 {

You can use "mac { ... }" to include any information which is specific to Mac OS. For example, the application icon which is specific for Mac OS, framework, or an Objective-C source file. Someone may use the style "else:win32{ ... }". I prefer the condition without "else:". Please note that "unix { ... }" has already included the case that this is a Mac machine, so if you have something works only on unix, you can use one of the two styles: "unix:!mac { ... }", or "mac { ... } else:unix { ... }"

2. Use qmake to generate makefile or project files for Visual Studio / XCode

qmake is a great command line tool, I used it to generate project files for my favorite IDE on different platforms: Visual Studio on Windows, xCode on Mac OS. I use Qt Creator as my IDE on Ubuntu.

On Windows, the command "qmake -tp vc" can generate vcxproj for Visual Studio 2010 or vcproj file for Visual Studio 2008 depending on your command line environment, or you can specify the version explicit by "-spec" parameter or by setting environment variable "QMAKESPEC". The "qmake -tp vc" means, use the templat prefix "vc" when run qmake for pro file, actually template prefix "vc" means generate Visual C++ project file.

On Mac, you the default behavior of "qmake" just generate xcode project file. So just run "qmake" under the folder with "pro" file.

You may also need to generate make file to make an automated building script. qmake can also do it perfectly. On Windows, the default behavior of "qmake" is to generate makefiles, and then you can follow with "nmake" or "nmake debug"/"nmake release". On mac, if you run "make", you may get the error message "make: *** No targets specified and no makefile found. Stop.", just run the command "qmake -spec macx-g++" to generate makefile: use "spec" parameter to specify the make spec "macx-g++" which will help you to generate makefile.

3. Handle application icons on Mac OS / Windows

On Windows, you need to have an "rc" file, and add an icon file. Please include this rc file for Windows only. On Mac, use the qmake internal variable "ICON' to specify the application icon. Please refer to the sample code above for more details.

4. C/C++ Cocoa/Carbon mixed module:

Sometimes you need to handle mixed module on Mac, that is, you may include Objective-C files in your project file. In Qt 4.7, there is still an issue if you want to generate xcode file. The bug has been logged to Nokia here: QTBUG-7953. Read the details in the bug report to get a solution, or wait for a future release.


  1. OH! I love your blog .Thank you for your share.By the way,i want to share a data recovery greenville sc to you!

  2. Wow, so thankful! I like your blog very much. By the way, you can choose some discount ray ban sunglasses here.