如何在cmake中使用QML_ELEMENT [英] How to use QML_ELEMENT with cmake

查看:88
本文介绍了如何在cmake中使用QML_ELEMENT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

doc 显示我可以使用QML_ELEMENT宏来创建通过在qmake的.pro文件中添加一些变量,从C ++生成QML类型.但是我在用cmake

The doc shows I can use QML_ELEMENT macro to create QML types from C++ by adding some variables in qmake's .pro file. But I'm using cmake

推荐答案

现在Qt 6.0已被支持,尽管文献记载不多.您现在需要的是:

Now that Qt 6.0 is out this is supported, albeit poorly documented. What you need now is:

set_target_properties(foo PROPERTIES
    QT_QML_MODULE_VERSION 1.0
    QT_QML_MODULE_URI     Foo
)

qt6_qml_type_registration(foo)

然后,您可以在qml中进行操作:

you can then do in qml:

import Foo

,您将可以访问具有 QML_ELEMENT 和朋友的类型.注意:

and you'll have access to types that have QML_ELEMENT and friends. Notes:

  • 在构建输出文件夹中创建了两个文件,分别是< project> _qmltyperegistrations.cpp < project> .qmltypes ,如果导入失败,则可以查看在那些看看哪些类型丢失.我发现有时需要在添加/删除注册类型之后进行完全重新编译.
  • Qt示例已迁移到cmake,因此请查看例如 Examples/Qt-6.0.0/quick/tableview/gameoflife 看到它的实际作用
  • 现在Qt源文件中的 pro2cmake.py run_pro2cmake.py 文件位于 Qt/6.0.0/Src/qtbase/util/cmake .在自述文件页中提到了它们,您可以在此处,我自己还没有尝试过.
  • Two files are created in the build output folder, <project>_qmltyperegistrations.cpp and <project>.qmltypes, if your imports are failing you can look at those to see which types are missing. I found that I needed to do full recompiles sometimes after adding/removing registered types.
  • Qt examples have been migrated to cmake, so take a look at e.g. Examples/Qt-6.0.0/quick/tableview/gameoflife to see it in action
  • There are now pro2cmake.py and run_pro2cmake.py files in the Qt sources at Qt/6.0.0/Src/qtbase/util/cmake. They are mentioned on this Readme page, you can find them here, haven't tried it myself.

这篇关于如何在cmake中使用QML_ELEMENT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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