Eclipse、QT 和“C++”项目》:可能吗?
需要您的帮助:
我想使用 Eclipse CDT 和 QT,而不创建“Qt gui 项目”。是否可以?如何将QT库包含到我的C++项目中,以及如何调用qmake/make来编译程序?这个类似问题没有帮不了我(
我想使用“C++ 项目”而不是“QT Gui 项目”,因为 QT 项目中的外部库索引存在问题(这个问题)
非常感谢! 尼古拉.
Need your help:
I want to use Eclipse CDT and QT without creating a "Qt gui project". Is it possible? How to include QT libraries to my C++ project, and how to call qmake/make to compile the program? This Similar question didn't help me(
I want to use 'C++ project' instead of 'QT Gui project' because there is an issue with external libraries indexing in the QT project (this problem)
Thank you a lot!
Nikolai.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我们使用 Qt 以及供应商定制版本的 Eclipse (Momentics) 和 CDT 做了类似的事情。为了让它工作,我们最终在 Eclipse 中使用我们自己的手工生成的 Makefile 创建了一个通用的 Makefile 项目。
手工生成的 Makefile 基本上包含足够的信息来在适当的 .pro 文件(“qt.pro”)上调用 QMake,然后调用生成的 Makefile(“qtmake.mk”)。
We've done something similar using Qt with a vendor customized version of Eclipse (Momentics) and CDT. To get it to work, we ended up creating a generic makefile project in Eclipse with our own, hand generated Makefile.
The hand generated Makefile basically contained enough information to invoke QMake on the appropriate .pro file ("qt.pro") and then invoke the resulting Makefile ("qtmake.mk").
这样做很麻烦,建议你不要这样做。我只在小项目上尝试过。
据我所知,您必须自己编写正确的 Makefile(或设置 CDT 来创建它),方法是包含 Qt 标头所需的所有包含路径。然后,您必须链接到您的项目正在使用的所有 Qt 库。
如果您使用 Qt 元对象系统,则必须在编译和链接之前运行 moc。 moc 生成 C++ 源代码,您必须将其链接到其他源。如果您正在使用 GNU make(我猜您正在使用 GNU make),那么似乎可以自动执行 moc,在 CDT 将创建的 Makefile 中写入正确的指令。有关详细信息,请阅读:http://doc .qt.io/qt-5/moc.html#writing-make-rules-for-invoking。
顺便问一下,你不能使用Qt Creator吗?
Doing this is quite bothering, I suggest you don't do it. I've tried it only on small projects.
As far as I know you'll have to write a correct Makefile yourself (or setup CDT to create it) by including all the include paths you need for Qt headers. Then you'll have to link to all the Qt libraries your project is using.
If you make use of the Qt meta-object system you'll have to run the moc before compiling and linking. The moc generates C++ sources that you'll have to link to the other sources. If you're using GNU make, and I guess you are, it seems to be possible to automate the moc writing the correct instructions in the Makefile CDT will create. For detailed information read this: http://doc.qt.io/qt-5/moc.html#writing-make-rules-for-invoking.
By the way, isn't it possible for you to use Qt Creator?
使用 Netbeans 非常容易,因为 qt 集成在 C++ 项目中。
但是,如果您使用 Eclipse,就像我的情况一样,您可以按照以下两个步骤操作(对于 Linux 用户):
寻找 。 -名称“.h” | sed 's/(.)(/)(.*)(.h)/moc-qt4 -D & -o \1\2moc_\3.cpp/' | sh
你必须在其中定义你想要的。只需运行一次,或者在项目目录中使用以下命令:
寻找 。 -name "moc_*.cpp" -exec -rm -f {} \;
顺便问一下,你尝试过qt插件吗?
J。
This is very easy making use of Netbeans, since qt is integrated in the c++ projects.
But if you use Eclipse, as is my case, you could follow these two steps (for linux users):
find . -name ".h" | sed 's/(.)(/)(.*)(.h)/moc-qt4 -D & -o \1\2moc_\3.cpp/' | sh
where you have to define the you want. Just run it once, or use the following command before from the project directory:
find . -name "moc_*.cpp" -exec -rm -f {} \;
By the way, have you tried the qt plugging?
J.
这是 jwernerny 的 makefile 的一个改进变体:
复制到另一个项目时不应对其进行编辑,实际上相同的规则已合并为一个。
Here is an improved variant of the jwernerny's makefile:
It should not to be edited when will be copied to another project, and actually the same rules was merged into one.