在QT Android app中使用QML文件,需要将QML文件包含到qrc资源文件中,否则发布时需要将qml文件一同发布。
引用qrc中的资源方法如下:
#include <QtGui/QGuiApplication>
#include <QQmlEngine>
#include <QQmlFileSelector>
#include <QQuickView>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQuickView view;
view.connect(view.engine(), SIGNAL(quit()), &app, SLOT(quit()));
new QQmlFileSelector(view.engine(), &view);
view.setSource(QUrl("qrc:///resource/Pickr.qml"));
view.setResizeMode(QQuickView::SizeRootObjectToView);
view.show();
return app.exec();
}
qrc资源如下图: