2

I don't make use of Qt Creator's UI design functionality.

For a new project, I'd like to experience working with Xcode. This will be a regular Qt project, developed using C++ and Qt libraries just like in Qt Creator.

I have no experience using OS X and especially Xcode.

  • What are the steps I need to follow to set up and use Xcode to develop a Qt application with support for Qt Framework? (ie. perhaps code completion or special errors etc.)

I have of course done my search but nothing seems to be clear about directions and not having any experience with OS X or Xcode makes it complicated so therefore I'd really appreciate your patient, step-by-step input for this. Various how-tos available online are not of satisfactory.

Platform: OS X, Qt 5.1

Thank you

Phil
  • 13,875
  • 21
  • 81
  • 126
  • you should be able to use a makefile check out what makefiles qmake generates (you'll need to run the [moc](http://qt-project.org/doc/qt-5.0/qtdoc/moc.html) at least) – ratchet freak Aug 28 '13 at 20:08
  • you can use qmake to generate xcode project. but you have to regenerate it again every time your add/remove new files – Bryan Chen Aug 28 '13 at 22:29
  • how can I integrate Qt framework though? i'd really appreciate any/all your help regarding this matter. thanks again! – Phil Aug 29 '13 at 16:32
  • 1
    Given that Qt creator's functionality goes well beyond "UI design", I don't think what you want is any good :( The big things you get with Qt creator are: 1. Integrated Qt documention. 2. Seamless debugging of QML and Javascript. 3. Debugging helpers for Qt types. 4. Building and deployment for multiple targets and/or Qt versions, including remote targets. 5. Integration with Valgrind and QML profiler. I use neither the UI designer nor QML designer, yet Qt Creator is still a big win. – Kuba hasn't forgotten Monica Sep 02 '13 at 16:46
  • Hello @KubaOber. You sound like a developer well experienced with Qt Creator. I'll take your word for it and stick with it. Thank you for your kind message. – Phil Sep 03 '13 at 10:02
  • 1
    One option is to use cmake -- it can generate XCode projects and has good support for Qt. I've done it. It works. – Ross Bencina Sep 05 '13 at 07:49
  • @KubaOber When you don't use any of those features the UX compared to XCode is horrible. – Appleshell Jun 10 '14 at 11:42
  • @Appleshell To me, coming from other IDEs (like Eclipse and VS), the outlier is Xcode where nothing works like anywhere else. It's a matter of taste, of course, but seriously, Xcode does *everything* its very own way, and they seem to purposefully invent their own ways of doing things just to do things their own way. The Project Builder legacy, 20 years later :/ – Kuba hasn't forgotten Monica Jun 10 '14 at 20:58

1 Answers1

2

You should have a look at CMake. It uses a simple language to define projects in text files and then generates the native project files for your environment (eg XCode).

Assuming your project structure looks like this: myproject/ MyProject.h MyProject.cpp main.cpp MyGui.ui

Add the following as CMakeLists.txt in the same directory:

cmake_mimimum_required( VERSION 2.8)

project( MyProject )

find_package( Qt4 COMPONENTS QtGui <insert components you need> REQUIRED)
include( ${QT_USE_FILE} )

# Qt's includes are already taken care of by the previous command
# add any additionaly include directories if required
# include "binary" dir to make sure the automatically generated files (eg for gui class) are found
include_directories( ${CMAKE_CURRENT_BINARY_DIR} )

# assuming MyProject contains a Q_OBJECT that needs to be processed by moc
QT4_WRAP_CPP( MOCS MyProject.h )   

QT4_WRAP_UI( UI MyGui.ui )

add_executable( MyProject 
      MyProject.cpp
      MyProject.h
      ${MOCS}
      ${UI}
)

target_link_libraries( MyProject ${QT_LIBRARIES} )

Create the "binary" directory. This directory will contain your XCode files and any files that are generated during the project (compiled objects etc). Thus, CMake allows easy separation of generated files from your source code so it doesn't mess up your source control.

In the binary directory, call:

cmake -G XCode <path to your source directory (where CMakeLists.txt is)>

You could also use the GUI tool CMake-Gui or console gui ccmake.

After cmake finished generating the project files, open them in XCode.

For more details, check the CMake documentation

Happy coding!

(Disclaimer: Code is untested.)

Johannes S.
  • 4,566
  • 26
  • 41
  • I haven't tested the code yet either and probably will stick with Qt Creator but this answer is a good starting point for all those keenly interested in the subject. Thank you for your kind help and time. – Phil Sep 06 '13 at 20:01