我试图从Qt 5.1.0安装程序导入TimeExample Qt快速扩展插件.
libqmlqtimeexampleplugin.so 是成功建造的 build-plugins-Android_for_arm_GCC_4_6_Qt_5_1_0-Debug/imports
然后我从Qt Creator创建了简单的Qt Quick2应用程序(内置元素).我应该在应用程序项目文件中添加什么来获取输出".apk"包中的QML插件?
现在它说:
W/Qt(23528):assets:/qml/TimeExampleTest/main.qml:2():assets:/qml/TimeExampleTest/main.qml:2:1:模块"TimeExample"未安装
main.qml
import QtQuick 2.0
import TimeExample 1.0 // import types from the plugin
Rectangle {
width: 360
height: 360
Text {
text: qsTr("Hello World")
anchors.centerIn: parent
}
MouseArea {
anchors.fill: parent
onClicked: {
Qt.quit();
}
}
Clock { // this class is defined in QML (imports/TimeExample/Clock.qml)
Time { // this class is defined in C++ (plugin.cpp)
id: time
}
hours: time.hour
minutes: time.minute
}
}
Run Code Online (Sandbox Code Playgroud)
TimeExampleTest.pro
folder_01.source = qml/TimeExampleTest
folder_01.target = qml
folder_02.source = /home/artem/Projects/Veedo/Test/build-plugins-Android_for_arm_GCC_4_6_Qt_5_1_0-Debug/imports/TimeExample
folder_02.target = imports
DEPLOYMENTFOLDERS = folder_01 folder_02
QML_IMPORT_PATH = /home/artem/Projects/Veedo/Test/build-plugins-Android_for_arm_GCC_4_6_Qt_5_1_0-Debug/imports/TimeExample
SOURCES += main.cpp
include(qtquick2applicationviewer/qtquick2applicationviewer.pri)
qtcAddDeployment()
OTHER_FILES += \
android/src/org/kde/necessitas/ministro/IMinistro.aidl \
android/src/org/kde/necessitas/ministro/IMinistroCallback.aidl \
android/src/org/qtproject/qt5/android/bindings/QtActivity.java \
android/src/org/qtproject/qt5/android/bindings/QtApplication.java \
android/AndroidManifest.xml \
android/version.xml \
android/res/values-ja/strings.xml \
android/res/values-rs/strings.xml \
android/res/values-zh-rTW/strings.xml \
android/res/values-fa/strings.xml \
android/res/values-ru/strings.xml \
android/res/values-fr/strings.xml \
android/res/values-ro/strings.xml \
android/res/values-el/strings.xml \
android/res/values-ms/strings.xml \
android/res/values-nb/strings.xml \
android/res/values-et/strings.xml \
android/res/values-pl/strings.xml \
android/res/values-pt-rBR/strings.xml \
android/res/values-es/strings.xml \
android/res/values-id/strings.xml \
android/res/values-de/strings.xml \
android/res/values-it/strings.xml \
android/res/values-zh-rCN/strings.xml \
android/res/values/strings.xml \
android/res/values/libs.xml \
android/res/layout/splash.xml \
android/res/values-nl/strings.xml
Run Code Online (Sandbox Code Playgroud)
在Qt 5.3中,我们通过将插件部署到官方Qt QML模块所在的QT_INSTALL_QML目录,设法通过Qt Android应用程序识别我们的QML插件.在我们的例子中,这个目录是/opt/Qt/5.3/android_armv7/qml.
插件方面
我们.pro的插件文件如下:
TEMPLATE = lib
TARGET = prova
QT += qml quick multimedia
CONFIG += qt plugin c++11 console
CONFIG -= android_install
TARGET = $$qtLibraryTarget($$TARGET)
uri = com.mycompany.qmlcomponents
# Input
SOURCES += \
src1.cpp \
src2.cpp
HEADERS += \
src1.h \
src2.h
##The below is generated automatically by Qt Creator when you create a new "Qt Quick 2 Extension Plugin" project for Android
#Copies the qmldir file to the build directory
!equals(_PRO_FILE_PWD_, $$OUT_PWD) {
copy_qmldir.target = $$OUT_PWD/qmldir
copy_qmldir.depends = $$_PRO_FILE_PWD_/qmldir
copy_qmldir.commands = $(COPY_FILE) \"$$replace(copy_qmldir.depends, /, $$QMAKE_DIR_SEP)\" \"$$replace(copy_qmldir.target, /, $$QMAKE_DIR_SEP)\"
QMAKE_EXTRA_TARGETS += copy_qmldir
PRE_TARGETDEPS += $$copy_qmldir.target
}
#Copies the qmldir file and the built plugin .so to the QT_INSTALL_QML directory
qmldir.files = qmldir
unix {
installPath = $$[QT_INSTALL_QML]/$$replace(uri, \\., /)
qmldir.path = $$installPath
target.path = $$installPath
INSTALLS += target qmldir
}
Run Code Online (Sandbox Code Playgroud)
我们qmldir(在插件源代码树根目录中)文件是:
module com.mycompany.qmlcomponents
plugin prova
Run Code Online (Sandbox Code Playgroud)
应用方面
.pro文件如下所示:
TEMPLATE = app
QT += qml quick widgets multimedia
CONFIG+= console
SOURCES += main.cpp
RESOURCES += qml.qrc
# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =
# Default rules for deployment.
include(deployment.pri)
contains(ANDROID_TARGET_ARCH,armeabi-v7a) {
ANDROID_EXTRA_LIBS = \
/opt/Qt/5.3/android_armv7/qml/com/mycompany/qmlcomponents/libprova.so
}
Run Code Online (Sandbox Code Playgroud)
我们实际上并不知道是否需要包含额外的libprova.so.这很可能不是.
的main.cpp样子:
#include <QApplication>
#include <QQmlApplicationEngine>
int main(int argc, char *argv[]){
QApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
return app.exec();
}
Run Code Online (Sandbox Code Playgroud)
该main.qml只包括像插件:
import QtQuick 2.2
import QtQuick.Controls 1.1
import QtMultimedia 5.0
import com.mycompany.qmlcomponents 1.0
...
Run Code Online (Sandbox Code Playgroud)
构建和部署
我们构建和部署插件的方式是qmake(来自Qt的android-armv7工具链)make install.它将qmldir文件和插件.so安装到QT_INSTALL_QML目录中.
我们构建和部署使用该插件的项目的方式是qmake(再次,来自Qt的android-armv7工具链),然后make install INSTALL_ROOT=.(安装到构建目录),然后运行androiddeployqt.最后一个命令使用资源/中的qmldirs和libs /中的库创建Android项目结构,并将整个内容捆绑在apk中ant.有关此过程的详细信息,请参阅http://qt-project.org/wiki/Android.
简而言之,我们只能通过将其放入私有Qt qml目录中来获取我们在Android项目中识别的QML插件.
| 归档时间: |
|
| 查看次数: |
3147 次 |
| 最近记录: |