2013-01-07 18 views
6

Qt5/QML paylaşılan kitaplığı QtCreator'daki "Libraries/Qt Quick 2 Extension Plugin" proje templeti kullanılarak bir test eklentisi oluşturdum. Gelişmekte olan ortamım Qt-5.0.0 ve QtCreator-2.6 ile linux'tur (detaylar aşağıya eklenir). (Ana fikir üzerine)Qt Quick 2 Uzantısı Eklentisi qmlscene (veya qmlviewer5) ile qq Quick 2 Extension Eklentisi Nasıl Kullanılır

kaynak dosyaları: https://gist.github.com/4467883

kaynak dosyaları varsayılan herhangi bir değişiklik olmadan üretilen vardır. Proje adı "adsız", uri "com.mycompany.mycomponents" ve Object Class-name "MyItem" dir. SRCDIR olarak "/ tmp/untitled" içindeki kaynak dosyaları.

Ve DestDir olarak "/ tmp/isimsiz-yapı" içinde, "qmldir" ve bazı nesne dosyaları "libuntitled.so" olarak çıktı kütüphane dosyasına kurmak.

$ 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 

Ama qmlscene komut test QML kaynağı olarak "/tmp/test/test.qml" nde kütüphane kullanamaz. (Ana fikir üzerine)

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

"test.qml": Bu başarısız oluyor https://gist.github.com/4474422

$ qmlscene test.qml 

ve QML_IMPORT_TRACE kayıtları:

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 

Ve dene "-I" seçenek:

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

, başarısız. log geçerli:

$ vim /tmp/test/qmldir 

"tmp/test/qmldir" (Ana fikir üzerine): var https://gist.github.com/4474497

başarısız

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 

Ve "/ tmp/test/qmldir" ile deneyin . log:

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 

Nasıl kütüphaneyi kullanmaya qmlscene (veya qmlviewer5) test .qml ("/ tmp/test.qml") olarak ("/ tmp/isimsiz oluşumu/libuntitled.so")?

Ortam ayrıntıları (openSUSE-12'ye göre).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 

Referanslar:

  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

cevap

4

deneyin koymak senin plugin.so ve 01 gibi bir klasörün içindedosyası:

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

sonra QML2_IMPORT_PATH ortam değişkeni imports dizin ekleyin. export QML2_IMPORT_PATH=/path/to/myproject/imports bu benim linux kutumda benim için çalıştı.

+0

Çok teşekkürler! Önemli noktalar şunlardır: (1) 'QML2_IMPORT_PATH' ortam değişkeni ayarlanır ve (2) uri bileşenine bağlı içe aktarım dizin ağacı yapısını ayarlayın. Çevremde çalışabilir. –

İlgili konular