Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. SetContextProperty and threading

SetContextProperty and threading

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.6k Views
  • 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 Offline
    S Offline
    SavageTwinky
    wrote on last edited by
    #1

    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
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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
      0
      • S Offline
        S Offline
        SavageTwinky
        wrote on last edited by
        #3

        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
        0
        • S Offline
          S Offline
          SavageTwinky
          wrote on last edited by
          #4

          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
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved