How to use Qt Quick 2 Extension Plugin on .qml with qmlscene (or qmlviewer5)

I created a test plugin as a Qt5 / QML shared library using the Qt Quick 2 Extension Plugin design library in QtCreator. My development environment is Linux with Qt-5.0.0 and QtCreator-2.6 (the detail is added below).

Source files (default): https://gist.github.com/4467883

Source files are generated by default without any changes . The project name is "untitled", uri is "com.mycompany.mycomponents", and the object class name is "MyItem". Source files in "/ tmp / untitled" as SRCDIR.

And create it to output the library file as "libuntitled.so", "qmldir" and some object files in "/ tmp / untitled-build" as 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 

But I can not use the library on the "/tmp/test/test.qml" page as a QML test source using the qmlscene command.

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

"test.qml" (default): https://gist.github.com/4474422

 $ qmlscene test.qml 

This is fail , and 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 

And try the "-I" option:

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

This one does not work . log:

 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 

And try using "/ tmp / test / qmldir":

 $ vim /tmp/test/qmldir 

"tmp / test / qmldir" (default): https://gist.github.com/4474497

This does not work . to come in:

 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 

How to use library ("/tmp/untitled-build/libuntitled.so") in test .qml ("/tmp/test.qml") with qmlscene (or qmlviewer5)?

Description of the environment (based on 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 

Literature:

+6
source share
1 answer

try putting your plugin.so and qmldir in a folder, for example:

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

then add the imports directory to the imports environment QML2_IMPORT_PATH . export QML2_IMPORT_PATH=/path/to/myproject/imports this worked for me in my Linux box.

+4
source

All Articles