Quantcast
Channel: Qt DevNet forums: Qt Quick 1283365070**
Viewing all articles
Browse latest Browse all 4972

Control qml ListView from C++

$
0
0
Hi there, I have two qml files from a designer (not me, I am not firm with qml). The loaded qml file is called main.qml the other mylistview.qml. import QtQuick 1.1   Item {     id: root     anchors.fill: parent       Item {         id: mainViewArea         anchors.fill: parent           Background {             id: background         }           ListView {             id: listView As you can think, the main.cpp loads the main.qml which includes the mylistview.qml that finally shows a ListView vertical. No Problem here. I use the following C++ code to load the QML. I cannot use QtQuick2 because no OpenGL on my embedded system: QDeclarativeView view; view.setSource(QUrl::fromLocalFile(QCoreApplication::applicationDirPath() + QLatin1String("/main.qml"))); I want to call the “incrementCurrentIndex” funktion of my listbox, but how? Can I search subfunktions with this: // get root object QObject *rootObject = dynamic_cast<QObject *>(view.rootObject()); //Invoke QMetaObject::invokeMethod(         rootObject->findChild<QObject *>("listView"), // QML item         "incrementCurrentIndex"                           // name of the method to call                                          // without parameters??     ); How do I call this in C++ after Invoke? Will the invoke find the mylistview.qml file? Do it find the increment function of a qml object?

Viewing all articles
Browse latest Browse all 4972

Trending Articles