Important: Please read the Qt Code of Conduct -

SetContextProperty and threading

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

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

    #ifdef TARGET
    return app->exec();

    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
    ProgressBar {
        id: progress
        x: 275
        y: 139
        value: sexyView.getProgressToQML
    Button {
        anchors.centerIn: parent
        onClicked: sexyView.runUpdate()



  • Lifetime Qt Champion


    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

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

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

Log in to reply