PDA

View Full Version : Unable to change the property after using Loader



rannamal
20th February 2012, 18:24
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);


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);


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"
}
}
}


Please let me know how i can overcome this problem.

rannamal
20th February 2012, 20:44
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.
progressQML->setProperty("value", 99);


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"));
progressQml->setProperty("value", 99);


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"
}
}
}


Please let me know how i can overcome this problem.

Please find the above modified code.

Is it just because i am updating a view which is different from the one loaded in the main.qml ?