How to set up Xcode to work with instead of Qt Creator?

你。 提交于 2019-12-10 10:47:21

问题


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


回答1:


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.)



来源:https://stackoverflow.com/questions/18500314/how-to-set-up-xcode-to-work-with-instead-of-qt-creator

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!