QtCreatorでプロジェクトテンプル "Libraries/Qt Quick 2 Extension Plugin"を使用してQt5/QML共有ライブラリとしてテストプラグインを作成しました。私の開発環境はQt-5.0.0とQtCreator-2.6のLinuxです(詳細は下に追加されています)。qmlscene(またはqmlviewer5)で.qmlにQt Quick 2 Extension Pluginを使用する方法
(要旨上の)ソースファイル:https://gist.github.com/4467883
ソースファイルは何も変更せずに生成デフォルトです。プロジェクト名は「タイトルなし」、uriは「com.mycompany.mycomponents」、オブジェクトクラス名は「MyItem」です。ソースファイルは "/ tmp/untitled"にSRCDIRとして格納されます。
そしてDESTDIRとして「を/ tmp /無題のビルド」で、「qmldir」と、いくつかのオブジェクトファイル「libuntitled.so」として出力ライブラリファイルにそれを構築します。
$ 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
しかし、私はqmlsceneコマンドを使用して、テストQMLソースとして "/tmp/test/test.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に/テスト/ qmldir" を試してみてください。
$ vim /tmp/test/qmldir
"TMP /テスト/ qmldir"(要旨上):https://gist.github.com/4474497
はを失敗だと。ログ:
qmlscene(またはqmlviewer5)でテスト.qml( "を/ tmp/test.qml")に( "を/ tmp /無題ビルド/ libuntitled.so")ライブラリを使用する方法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
?
環境の詳細(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にリンクされたインポートディレクトリツリー構造を設定することです。私の環境で実行できます。 –