我在QtCreator中使用項目模板「Libraries/Qt Quick 2 Extension Plugin」創建了一個測試插件作爲Qt5/QML共享庫。我的開發環境是使用Qt-5.0.0和QtCreator-2.6的Linux(細節在底部附加)。如何在qqlscene(或qmlviewer5)上使用.qml上的Qt Quick 2擴展插件
源文件(在GIST):https://gist.github.com/4467883
源文件是不作任何修改產生默認。項目名稱是「untitled」,uri是「com.mycompany.mycomponents」,而Object Class-name是「MyItem」。 「/ tmp/untitled」中的源文件作爲SRCDIR。
它建立到輸出庫文件作爲「libuntitled.so」,「qmldir」和一些對象「的/ tmp /無建造」文件作爲DESTDIR。
$ 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」(上GIST):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 /測試/ qmldir」(上GIST):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」)與qmlscene(或qmlviewer5)( 「/ tmp目錄/無建造/ libuntitled.so」)?
環境細節(基於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
參考文獻:
- http://doc-snapshot.qt-project.org/5.0/qtcore/plugins-howto.html
- http://doc-snapshot.qt-project.org/5.0/qtcore/qtplugin.html
- http://qt-project.org/doc/qt-5.0/qtqml/qtqml-modules-qmldir.html
- http://qt-project.org/doc/qt-5.0/qtqml/examples-quick-tutorials-extending-chapter6-plugins.html
非常感謝!重點是(1)設置環境變量'QML2_IMPORT_PATH'和(2)設置鏈接到組件uri的導入目錄樹結構。它可以運行在我的環境中。 –