Developing QT applications in Xcode?

Benjamin picture Benjamin · Oct 18, 2011 · Viewed 21.5k times · Source

My IDE of choice for the Mac (at least for C++ and Objective-C development) is Xcode. I have a 64-bit Intel Mac with OS X Lion installed, and Xcode version 4.2 downloaded from the Mac App Store.
My problem is that Qt is apparently not compatible with Xcode 4 (it crashes when launching projects generated by qmake), so I'm basically asking how I can integrate Qt with Xcode. I don't have to be able to run and debug the project from Xcode, just build it.
So I thought it might be a solution to use qmake as an external build system within Xcode, the problem is that I have no idea how to set up qmake as my build system, so that I can develop my Qt applications in Xcode 4.
Please help me! :)

Answer

Clare Macrae picture Clare Macrae · Oct 18, 2011

Google shows up many pages, but this Qt4 with Xcode page appeared at first glance to be a fairly definitive resource. However, it was last changed in 2006.

Please check out: http://qt-project.org/doc/qt-5/macosx.html

There is a much more recent Qt Developer Network forum post that seems to have good info in it. Specifically, this reply from August 19, 2011 gives a complete recipe.


Update 25/05/2016:

The first two links are now dead, and not archived due to robots.txt.

However, I've updated the link to the forum post.

And here's a copy of emiguel's answer. It is now 5 years old, so I don't know how current it still is.

Hi,

To solve my problem I did the following.

First I`m going to have a subproject in Qt that mantains the graphical interface, I created this project as a C++ library, so I could include this in the main project.

The main project is a C++ project in Xcode (which is a plugin template with a lot of configurations).

Second, I ported the Qt project to Xcode using the spec macx-xcode parameter.

Third, having both projects in Xcode, I can attatch the library (in Qt) to the main project. To do this, right click in the xcode project and click in the "existing file..." option, select the xcodeproj file from the Qt project. Finally add the library to the linkage phase, this is done by dragging the lib file, wich is under the xcodeproj file, to the "Targets" section in the "Link binary with Libraries".

Fourth, import the Qt framewoks to the main project, to do that, right click in the main project, click in add a existing framework, select the Qt features used by the project (ex. QtSDK/lib/QtCore.framework)

And finally, add the header and library paths in the main project. Click in project menu->project settings, set the header search paths option with the Qt headers (ex QtSDK/include//) and the library search paths (ex QtSDK/lib//**).

That's all, now I can instantiate my own Qt widgets from the C++ project.

Note: I have to do an additional step because my target was i386 and the downloaded Qt version were 64 bit, so I downloaded the sources and compiled it for i386.

Now I have another problems about drawing inner the plugin... but I think that will be for another post.

Thanks a lot for your help

Finally, current information on building Qt in Xcode is available in Qt for OS X - which is too long to copy here, and will be maintained and updated by Qt...