Results 1 to 2 of 2

Thread: Unable to change the property after using Loader

  1. #1

    Default Unable to change the property after using Loader

    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.

    Qt Code:
    1. QDeclarativeView* progressView = new QDeclarativeView;
    2. progressView->setSource(QUrl("Progressbar.qml"));
    3. setCentralWidget(progressView);
    4.  
    5. QObject *rootObject = dynamic_cast<QObject *>(progressView->rootObject());
    6. QObject *progressQml = rootObject->findChild<QObject *>(QString("progressBar")); //progressBar is the name of the progressbar object.
    7. 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.

    Qt Code:
    1. QDeclarativeView* mainView = new QDeclarativeView;
    2. mainView->setSource(QUrl("main.qml"));
    3. setCentralWidget(mainView);
    4.  
    5. QDeclarativeView* progressView = new QDeclarativeView;
    6. progressView->setSource(QUrl("Progressbar.qml"));
    7. QObject *rootObject = dynamic_cast<QObject *>(progressView->rootObject());
    8. QObject *progressQml = rootObject->findChild<QObject *>(QString("progressBar"));
    9. image->setProperty("value", 99);
    To copy to clipboard, switch view to plain text mode 

    The main.qml file contents are as follwos.

    Qt Code:
    1. import QtQuick 1.0
    2.  
    3. Rectangle {
    4. id: rect
    5. width: 400; height: 400
    6. color: "yellow"
    7.  
    8. Loader {
    9. id:someLoader
    10. }
    11.  
    12. MouseArea {
    13. anchors.fill: parent
    14. onClicked: {
    15. someLoader.source = "Progressbar.qml"
    16. }
    17. }
    18. }
    To copy to clipboard, switch view to plain text mode 

    Please let me know how i can overcome this problem.

  2. #2

    Default Re: Unable to change the property after using Loader

    Quote Originally Posted by rannamal View Post
    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.

    Qt Code:
    1. QDeclarativeView* progressView = new QDeclarativeView;
    2. progressView->setSource(QUrl("Progressbar.qml"));
    3. setCentralWidget(progressView);
    4.  
    5. QObject *rootObject = dynamic_cast<QObject *>(progressView->rootObject());
    6. QObject *progressQml = rootObject->findChild<QObject *>(QString("progressBar")); //progressBar is the name of the progressbar object.
    7. progressQML->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.

    Qt Code:
    1. QDeclarativeView* mainView = new QDeclarativeView;
    2. mainView->setSource(QUrl("main.qml"));
    3. setCentralWidget(mainView);
    4.  
    5. QDeclarativeView* progressView = new QDeclarativeView;
    6. progressView->setSource(QUrl("Progressbar.qml"));
    7. QObject *rootObject = dynamic_cast<QObject *>(progressView->rootObject());
    8. QObject *progressQml = rootObject->findChild<QObject *>(QString("progressBar"));
    9. progressQml->setProperty("value", 99);
    To copy to clipboard, switch view to plain text mode 

    The main.qml file contents are as follwos.

    Qt Code:
    1. import QtQuick 1.0
    2.  
    3. Rectangle {
    4. id: rect
    5. width: 400; height: 400
    6. color: "yellow"
    7.  
    8. Loader {
    9. id:someLoader
    10. }
    11.  
    12. MouseArea {
    13. anchors.fill: parent
    14. onClicked: {
    15. someLoader.source = "Progressbar.qml"
    16. }
    17. }
    18. }
    To copy to clipboard, switch view to plain text mode 

    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 ?

Similar Threads

  1. Replies: 5
    Last Post: 3rd July 2014, 13:46
  2. Replies: 1
    Last Post: 20th January 2011, 18:17
  3. Replies: 1
    Last Post: 18th November 2010, 08:39
  4. Change Stylesheet Using Dynamic Property
    By stefanadelbert in forum Qt Programming
    Replies: 4
    Last Post: 26th August 2010, 08:48
  5. How to mark Property name in Q_PROPERTY for language change??
    By Ankitha Varsha in forum Qt Programming
    Replies: 7
    Last Post: 14th April 2010, 14:22

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.