Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    SetContextProperty and threading

    General and Desktop
    2
    4
    1321
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      SavageTwinky last edited by

      I'm having a small issue with creating an object on a thread as well as setting it as a property in a qml view. I'm just wondering why this doesn't work. I want the qml view to update while the work is being done but it does not.

      main .cpp
      @
      // create update thread
      QThread sexyThread;
      Sexy sexyWork;
      sexyWork.moveToThread(&sexyThread);
      updateThread.start();

      // create view
      QDeclarativeView view;
      // hook up the update class to the view
      view.rootContext()->setContextProperty("sexyView", &sexyWork);
      
      // set the main view
      view.setSource(QUrl("qrc:QML/main.qml"));
      

      #ifdef TARGET
      view.showFullScreen();
      #else
      view.show();
      #endif
      return app->exec();
      @

      main.qml
      @
      import Qt 4.7

      Rectangle {
      width: 800; height: 480

      Connections {
          target: sexyView
      }
      
      Text {
          id: statusText
          x: 327
          y: 91
          text: sexyView.getStatusToQML
          anchors.topMargin: 91
          anchors.top: parent.top
      }
      
      ProgressBar {
          id: progress
          x: 275
          y: 139
          value: sexyView.getProgressToQML
      }
      
      Button {
          anchors.centerIn: parent
          onClicked: sexyView.runUpdate()
      }
      

      }

      @

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

        Did you check that the property name you are using in setContextProperty is the same as the one you have in your QML ? Here for example "sexyView" and you are giving it your worker object.

        Posting your QML code would also help

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 0
        • S
          SavageTwinky last edited by

          Yah everything works fine, it's just I don't get the gui updates until the very end sorry for not clarifying that.

          1 Reply Last reply Reply Quote 0
          • S
            SavageTwinky last edited by

            i'm guessing I can't tie a threaded object directly as a context property? i'll just find another way to do this

            1 Reply Last reply Reply Quote 0
            • First post
              Last post