Hi ,
I am new to QML, please pardon me if its a very obvious question.
I have created a progress bar element using QML and i am able to update the value of the progress bar by the following code.
QDeclarativeView* progressView = new QDeclarativeView;
progressView
->setSource
(QUrl("Progressbar.qml"));
setCentralWidget(progressView);
QObject *rootObject
= dynamic_cast<QObject
*>
(progressView
->rootObject
());
QObject *progressQml
= rootObject
->findChild<QObject
*>
(QString("progressBar"));
//progressBar is the name of the progressbar object. image->setProperty("value", 99);
QDeclarativeView* progressView = new QDeclarativeView;
progressView->setSource(QUrl("Progressbar.qml"));
setCentralWidget(progressView);
QObject *rootObject = dynamic_cast<QObject *>(progressView->rootObject());
QObject *progressQml = rootObject->findChild<QObject *>(QString("progressBar")); //progressBar is the name of the progressbar object.
image->setProperty("value", 99);
To copy to clipboard, switch view to plain text mode
The issue is, I am not able to update the view if i load the "Progressbar.qml" from another file "Main.qml" using the loader functionality. Code with issue is as follows.
QDeclarativeView* mainView = new QDeclarativeView;
mainView
->setSource
(QUrl("main.qml"));
setCentralWidget(mainView);
QDeclarativeView* progressView = new QDeclarativeView;
progressView
->setSource
(QUrl("Progressbar.qml"));
QObject *rootObject
= dynamic_cast<QObject
*>
(progressView
->rootObject
());
QObject *progressQml
= rootObject
->findChild<QObject
*>
(QString("progressBar"));
image->setProperty("value", 99);
QDeclarativeView* mainView = new QDeclarativeView;
mainView->setSource(QUrl("main.qml"));
setCentralWidget(mainView);
QDeclarativeView* progressView = new QDeclarativeView;
progressView->setSource(QUrl("Progressbar.qml"));
QObject *rootObject = dynamic_cast<QObject *>(progressView->rootObject());
QObject *progressQml = rootObject->findChild<QObject *>(QString("progressBar"));
image->setProperty("value", 99);
To copy to clipboard, switch view to plain text mode
The main.qml file contents are as follwos.
import QtQuick 1.0
Rectangle {
id: rect
width: 400; height: 400
color: "yellow"
Loader {
id:someLoader
}
MouseArea {
anchors.fill: parent
onClicked: {
someLoader.source = "Progressbar.qml"
}
}
}
import QtQuick 1.0
Rectangle {
id: rect
width: 400; height: 400
color: "yellow"
Loader {
id:someLoader
}
MouseArea {
anchors.fill: parent
onClicked: {
someLoader.source = "Progressbar.qml"
}
}
}
To copy to clipboard, switch view to plain text mode
Please let me know how i can overcome this problem.
Bookmarks