gpt4 book ai didi

c++ - 如何在带有 qmlscene(或 qmlviewer5)的 .qml 上使用 Qt Quick 2 扩展插件

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:38:19 24 4
gpt4 key购买 nike

我在 QtCreator 中使用项目模板“Libraries/Qt Quick 2 Extension Plugin”创建了一个测试插件作为 Qt5/QML 共享库。我的开发环境是linux,Qt-5.0.0和QtCreator-2.6(详情见底部)。

源文件(在要点上):https://gist.github.com/4467883

源文件是默认生成的,没有任何更改。项目名称是“无标题”,uri 是“com.mycompany.mycomponents”,对象类名称是“MyItem”。 “/tmp/untitled”中的源文件作为 SRCDIR。

并将其构建为输出库文件作为 "libuntitled.so""qmldir" 以及作为 DESTDIR 的 "/tmp/untitled-build"中的一些目标文件.

$ ls /tmp/untitled-build
Makefile libuntitled.so moc_myitem.cpp
moc_myitem.o moc_untitled_plugin.cpp moc_untitled_plugin.o myitem.o
qmldir untitled_plugin.o

但是,我不能使用位于“/tmp/test/test.qml”的库作为带有 qmlscene 命令的测试 QML 源。

$ mkdir /tmp/test; cd /tmp/test
$ vim test.qml

“test.qml”(要点):https://gist.github.com/4474422

$ qmlscene test.qml

失败QML_IMPORT_TRACE日志为:

QQmlImportDatabase::addImportPath: "/usr/lib64/qt5/qml"
QQmlImportDatabase::addImportPath: "/usr/bin"
QQmlImports(file:///tmp/test/test.qml)::addImplicitImport
QQmlImports(file:///tmp/test/test.qml)::addLibraryImport: "QtQuick" 2.0 as ""
QQmlImports(file:///tmp/test/test.qml)::importExtension: loaded "/usr/lib64/qt5/qml/QtQuick.2/qmldir"
QQmlImportDatabase::importPlugin: "QtQuick" from "/usr/lib64/qt5/qml/QtQuick.2/libqtquick2plugin.so"
file:///tmp/test/test.qml:2 module "com.mycompany.mycomponents" is not installed

然后尝试“-I”选项:

$ qmlscene test.qml -I /tmp/untitled-build

那也是失败。日志是:

QQmlImportDatabase::addImportPath: "/usr/lib64/qt5/qml"
QQmlImportDatabase::addImportPath: "/usr/bin"
QQmlImportDatabase::addImportPath: "/tmp/untitled-build"
QQmlImports(file:///tmp/test/test.qml)::addImplicitImport
QQmlImports(file:///tmp/test/test.qml)::addLibraryImport: "QtQuick" 2.0 as ""
QQmlImports(file:///tmp/test/test.qml)::importExtension: loaded "/usr/lib64/qt5/qml/QtQuick.2/qmldir"
QQmlImportDatabase::importPlugin: "QtQuick" from "/usr/lib64/qt5/qml/QtQuick.2/libqtquick2plugin.so"
file:///tmp/test/test.qml:2 module "com.mycompany.mycomponents" is not installed

然后尝试使用“/tmp/test/qmldir”:

$ vim /tmp/test/qmldir

“tmp/test/qmldir”(要点):https://gist.github.com/4474497

那是失败。日志:

QQmlImportDatabase::addImportPath: "/usr/lib64/qt5/qml"
QQmlImportDatabase::addImportPath: "/usr/bin"
QQmlImports(file:///tmp/test/test.qml)::addImplicitImport
QQmlImports(file:///tmp/test/test.qml)::importExtension: loaded "/tmp/test/qmldir"
QQmlImportDatabase::importPlugin: ".tmp.test" from "/tmp/untitled-build/libuntitled.so"
Module '.tmp.test' does not contain a module identifier directive - it cannot be protected from external registrations.
QQmlImports(file:///tmp/test/test.qml)::addLibraryImport: "QtQuick" 2.0 as ""
QQmlImports(file:///tmp/test/test.qml)::importExtension: loaded "/usr/lib64/qt5/qml/QtQuick.2/qmldir"
QQmlImportDatabase::importPlugin: "QtQuick" from "/usr/lib64/qt5/qml/QtQuick.2/libqtquick2plugin.so"
file:///tmp/test/test.qml:2 module "com.mycompany.mycomponents" is not installed

如何在测试.qml("/tmp/test.qml") 中使用库("/tmp/untitled-build/libuntitled.so") 与qmlscene (或qmlviewer5)?

环境细节(基于 openSUSE-12.2):

$ uname -a
Linux LH-MAIN 3.4.11-2.16-desktop #1 SMP PREEMPT Wed Sep 26 17:05:00 UTC 2012 (259fc87) x86_64 x86_64 x86_64 GNU/Linux
$ g++ --version | head -n1
g++ (SUSE Linux) 4.7.1 20120723 [gcc-4_7-branch revision 189773]
$ qmake -v
QMake version 3.0
Using Qt version 5.0.0 in /usr/lib64
$ qtcreator -version 2>&1 >/dev/null | grep "^[^ ].*" | head -n1
Qt Creator 2.6.1 based on Qt 5.0.0
$ qmlviewer5 -v
Qml debugging is enabled. Only use this in a safe environment!
Qt QML Viewer version 5.0.0

引用资料:

  1. http://doc-snapshot.qt-project.org/5.0/qtcore/plugins-howto.html
  2. http://doc-snapshot.qt-project.org/5.0/qtcore/qtplugin.html
  3. http://qt-project.org/doc/qt-5.0/qtqml/qtqml-modules-qmldir.html
  4. http://qt-project.org/doc/qt-5.0/qtqml/examples-quick-tutorials-extending-chapter6-plugins.html

最佳答案

尝试将您的 plugin.soqmldir 文件放在如下文件夹中:

- myproject
- imports
- com
- mycompany
- mycomponents
- libuntitled.so
- qmldir

然后将imports 目录添加到QML2_IMPORT_PATH 环境变量中。export QML2_IMPORT_PATH=/path/to/myproject/imports这在我的 linux 机器上对我有用。

关于c++ - 如何在带有 qmlscene(或 qmlviewer5)的 .qml 上使用 Qt Quick 2 扩展插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14196070/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com