C++ 在 Xcode 中开发 QT 应用程序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7812083/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Developing QT applications in Xcode?
提问by Benjamin
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! :)
我为 Mac 选择的 IDE(至少对于 C++ 和 Objective-C 开发)是 Xcode。我有一台安装了 OS X Lion 的 64 位 Intel Mac,以及从 Mac App Store 下载的 Xcode 4.2 版。
我的问题是 Qt 显然与 Xcode 4 不兼容(它在启动 qmake 生成的项目时崩溃),所以我基本上是在问如何将 Qt 与 Xcode 集成。我不必能够从 Xcode 运行和调试项目,只需构建它。
所以我认为在 Xcode 中使用 qmake 作为外部构建系统可能是一个解决方案,问题是我不知道如何将 qmake 设置为我的构建系统,以便我可以在 Xcode 4 中开发我的 Qt 应用程序。
请帮我!:)
采纳答案by Clare Macrae
Google shows up many pages, but this Qt4 with Xcodepage appeared at first glance to be a fairly definitive resource. However, it was last changed in 2006.
Google 显示了许多页面,但是这个带有 Xcode 的 Qt4页面乍一看似乎是一个相当确定的资源。但是,它最后一次更改是在 2006 年。
Please check out: http://qt-project.org/doc/qt-5/macosx.html
请查看:http: //qt-project.org/doc/qt-5/macosx.html
There is a much more recent Qt Developer Network forum postthat seems to have good info in it. Specifically, this reply from August 19, 2011gives a complete recipe.
有一个更新的Qt Developer Network 论坛帖子,其中似乎有很好的信息。具体来说,2011年8月19日的这个回复给出了一个完整的秘诀。
Update 25/05/2016:
25/05/2016 更新:
The first two links are now dead, and not archived due to robots.txt
.
前两个链接现已失效,由于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.
这是艾米格尔答案的副本。现在已经5岁了,所以我不知道它现在怎么样了。
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
你好,
为了解决我的问题,我做了以下事情。
首先,我将在 Qt 中创建一个维护图形界面的子项目,我将此项目创建为 C++ 库,因此我可以将其包含在主项目中。
主工程是Xcode中的C++工程(是一个插件模板,配置很多)。
其次,我使用spec macx-xcode 参数将Qt 项目移植到Xcode。
第三,在 Xcode 中拥有两个项目,我可以将库(在 Qt 中)附加到主项目。为此,请右键单击 xcode 项目并单击“现有文件...”选项,从 Qt 项目中选择 xcodeproj 文件。最后将库添加到链接阶段,这是通过将位于 xcodeproj 文件下的 lib 文件拖到“Link binary with Libraries”中的“Targets”部分来完成的。
四、将Qt框架导入到主项目中,为此,在主项目中右键单击,单击添加现有框架,选择项目使用的Qt功能(例如QtSDK/lib/QtCore.framework)
最后,在主项目中添加头文件和库路径。单击项目菜单-> 项目设置,使用 Qt 头文件(例如 QtSDK/include//)和库搜索路径(例如 QtSDK/lib//**)设置头文件搜索路径选项。
就是这样,现在我可以从 C++ 项目中实例化我自己的 Qt 小部件。
注意:我必须做一个额外的步骤,因为我的目标是 i386 并且下载的 Qt 版本是 64 位,所以我下载了源代码并为 i386 编译了它。
现在我有另一个关于在插件内部绘制的问题......但我认为那将是另一篇文章。
非常感谢你的帮助
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...
最后,关于在 Xcode 中构建 Qt 的当前信息在OS X 的Qt 中可用- 在这里复制太长,将由 Qt 维护和更新......