如何链接QtMain在CMake与Qt5? [英] How to link QtMain in CMake with Qt5?

查看:632
本文介绍了如何链接QtMain在CMake与Qt5?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将我的项目代码从Qt4升级到Qt5。它使用CMake。
转换得到很好,除了与Qt相关的一行Cmake命令。
我无法当前文档中发现,像





如何从CMake的(与QT5)?与QtMain链接



这是转换我的项目唯一缺少的位。
有人可能指向我一个文档解释这个或解释如何做它与Qt5?我的Qt4代码工作正常,但我不能找到QT5 CMake的宏



编辑>下面是CMake的文件,我在那一刻:的https://bitbucket.org/klaim/aos_qt5/src/593c195c4c6889f6968d68fca018ef425783a063/tools/aosdesigner/CMakeLists .txt文件?在= wip_qt5



必要的CMake宏已正确设置我相信所有QT5,只是不工作的事情是链接到QtMain什么也不做,因为期望的,因为应该有这样做的QT5具体办法,我没有在QT5文档中找到。



您可以浏览文件历史看它是如何与Qt4的工作。


解决方案

从的 Qt的文档你的联系,似乎你可以找到Qt5Core而不是Qt5Widgets。这将创建一个名为 Qt5 :: WinMain 的导入目标。从 Qt文档


为每个Qt模块创建导入的目标。这意味着 Qt5< Module> _LIBRARIES 包含导入目标的名称,而不是库的路径。

... < Qt 5中的每个模块都有一个命名约定为 Qt5 ::< Module>

的库目标

blockquote>

   find_package(Qt5Widgets REQUIRED) 
find_package(Qt5Core REQUIRED)
...
add_executable(aosdesigner WIN32 $ {AOSDESIGNER_ALL_FILES})
target_link_libraries(aosdesigner
$ {Boost_LIBRARIES}
utilcpp
aoslcpp
Qt5 :: WinMain#< - 新目标可通过find_package(Qt5Core)


qt5_use_modules(aosdesigner Widgets)

我还建议您删除两个 link_libraries 呼叫,因为它是已弃用的命令,我将指定CMake版本2.8.9,而不是仅仅2.8作为您的CMakeLists顶部所需的最低要求。 txt,因为 qt5_use_modules


I upgraded my project code from Qt4 to Qt5. It uses CMake. The conversion got well except for one line of Cmake commands related to Qt. I can’t find in current documentation, like

How to link with QtMain from CMake (with Qt5)?

It is the only missing bit to convert my project. Can someone point me to a doc explaining this or explain how to do it with Qt5? My Qt4 code worked correctly but I can't find the Cmake macro for Qt5.

EDIT> Here is the CMake file I have at the moment: https://bitbucket.org/klaim/aos_qt5/src/593c195c4c6889f6968d68fca018ef425783a063/tools/aosdesigner/CMakeLists.txt?at=wip_qt5

All qt5 necessary CMake macros have been set correctly I belive, the only thing that don't work is the linking to QtMain that do nothing, as expected since there should be a Qt5 specific way of doing it that I don't find in the Qt5 documentation.

You can browse the file history to see how it was working with Qt4.

解决方案

From the Qt docs you linked to, it seems you can find Qt5Core instead of Qt5Widgets. That will create an imported target named Qt5::WinMain. From the Qt docs:

Imported targets are created for each Qt module. That means that the Qt5<Module>_LIBRARIES contains a name of an imported target, rather than a path to a library.
...
Each module in Qt 5 has a library target with the naming convention Qt5::<Module>

find_package( Qt5Widgets REQUIRED )
find_package( Qt5Core REQUIRED )
...
add_executable( aosdesigner WIN32 ${AOSDESIGNER_ALL_FILES} )
target_link_libraries( aosdesigner
    ${Boost_LIBRARIES}
    utilcpp
    aoslcpp
    Qt5::WinMain  # <-- New target available via find_package ( Qt5Core )
)

qt5_use_modules( aosdesigner Widgets )

I'd also recommend that you remove your two link_libraries calls since it's a deprecated command and I'd specify CMake version 2.8.9 rather than just 2.8 as the minimum required at the top of your CMakeLists.txt, since that's required for qt5_use_modules.

这篇关于如何链接QtMain在CMake与Qt5?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆