in my android application i want to show a list of links.
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
LinkListModel social_links;
social_links.get(content_category::social);
QQuickView view;
view.setResizeMode(QQuickView::SizeRootObjectToView);
QQmlContext *ctxt = view.rootContext();
ctxt->setContextProperty("myModel", &social_links);
view.setSource(QUrl("qrc:main.qml"));
view.show();
return app.exec();
}
This is my .qml file:
import QtQuick 2.0
import QtQuick.Controls 1.1
ApplicationWindow {
id: mainWindow
visible: true
width: 640
height: 480
menuBar: MenuBar {
Menu {
MenuItem {
text: qsTr("Exit")
onTriggered: Qt.quit();
}
}
}
ListView {
width: 640
height: 480
model: myModel
delegate: Rectangle {
height: 25
width: 100
Text { text: "modelData: " + title }
}
}
}
I don't show my model class as it does not matter for my problem. When I want to run the application in the emulator i get the following error message and the application aborts:
W/EGL_emulation( 6582): eglSurfaceAttrib not implemented
W/Qt ( 6582): items\qquickview.cpp:518 (void QQuickViewPrivate::setRootObject(QObject*)): QQuickView only supports loading of root objects that derive from QQuickItem.
W/Qt ( 6582):
W/Qt ( 6582): If your example is using QML 2, (such as qmlscene) and the .qml file you
W/Qt ( 6582): loaded has 'import QtQuick 1.0' or 'import Qt 4.7', this error will occur.
W/Qt ( 6582):
W/Qt ( 6582): To load files with 'import QtQuick 1.0' or 'import Qt 4.7', use the
W/Qt ( 6582): QDeclarativeView class in the Qt Quick 1 module.
W/Qt ( 6582):
F/libc ( 6582): Fatal signal 11 (SIGSEGV) at 0x2a43e000 (code=1), thread 6582 (.example.AKBApp)
Does anyone know what I am doing wrong?
QQuickView
only supports loading of root objects that derive from QQuickItem
. ApplicationWindow
derived from QQuickWindow
. You should use QQmlApplicationEngine instead of QQuickView
.
QApplication app(argc, argv);
LinkListModel social_links;
social_links.get(content_category::social);
QQmlApplicationEngine engine;
engine.rootContext()->setContextProperty("myModel", &social_links);
engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
return app.exec();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.