Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Set property values by importing data to ValueSource.qml from different Thread/Runtime
QtWS25 Last Chance

Set property values by importing data to ValueSource.qml from different Thread/Runtime

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 2 Posters 368 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.
  • P Offline
    P Offline
    Philomath-Qt
    wrote on last edited by
    #1

    Hello,
    is there a way to make the Qt Extras Example Dashboard import it's values from a different thread?

    The dashboard has the qml file dashboard.qml which runs looping sequential and parallel animations to set values of the properties. Only difference to the example is that i converted it to run with cmake with a CMakeLists.txt file instead of a *pro qmake project.

    Instead of setting the values of the properties in this looping animations, i want them to be imported from a .hpp file that is running in a different thread.

    In my main.cpp i run two threads, one to start the dashboard and a separate one, that receives data from outside the system by running a process in a own runtime. In this separate thread runs a looping function in a .hpp file, that sets the values of some integer variables.
    I already know about the usage of lockguards in C++ to make two different threads write and read the same variable, but i don't know how to accomplish this in the qml file and if this is even possible.

    Any advice on how to get the data from the .hpp file to be displayed on my dashboard?
    I'm also happy to hear any suggestions, that use a completely different approach.

    Thank you in advance & kind reagards

    DiracsbracketD 1 Reply Last reply
    0
    • P Offline
      P Offline
      Philomath-Qt
      wrote on last edited by Philomath-Qt
      #4

      Hi there,
      i found an utterly easy solution to exercise everyhting with using a QObject, wihtout having to use QThread.
      In my main.cpp started i start my GUI after the separat runtime using std::thread.
      I created a QObject in a .hpp and .cpp class with a slot and a signal. I had to add

      QQmlContext* context = engine.rootContext();
       context->setContextProperty("signalData", separat_process.pointer);
       engine.load(QUrl("qrc:/qml/dashboard.qml"));
      

      to my main to connect my GUI to the Object. In the separat_process i use the slots of the QObject which triggers signals.
      Then i had to add

          Connections {
              target: signalData
              function onXYZ(abc) {
                  //something happens
              }
              function onXYZ(abc) {
               //something else happens
              }
          }
      

      to my GUI Item.

      1 Reply Last reply
      0
      • P Philomath-Qt

        Hello,
        is there a way to make the Qt Extras Example Dashboard import it's values from a different thread?

        The dashboard has the qml file dashboard.qml which runs looping sequential and parallel animations to set values of the properties. Only difference to the example is that i converted it to run with cmake with a CMakeLists.txt file instead of a *pro qmake project.

        Instead of setting the values of the properties in this looping animations, i want them to be imported from a .hpp file that is running in a different thread.

        In my main.cpp i run two threads, one to start the dashboard and a separate one, that receives data from outside the system by running a process in a own runtime. In this separate thread runs a looping function in a .hpp file, that sets the values of some integer variables.
        I already know about the usage of lockguards in C++ to make two different threads write and read the same variable, but i don't know how to accomplish this in the qml file and if this is even possible.

        Any advice on how to get the data from the .hpp file to be displayed on my dashboard?
        I'm also happy to hear any suggestions, that use a completely different approach.

        Thank you in advance & kind reagards

        DiracsbracketD Offline
        DiracsbracketD Offline
        Diracsbracket
        wrote on last edited by Diracsbracket
        #2

        Hi. @Philomath-Qt
        I faced the same problem. Have a look at my question at https://forum.qt.io/topic/122174/how-to-eliminate-msleep-from-a-worker-thread-and-use-a-timer-in-the-gui-thread-instead
        It describes how I first tried to implement a C++ thread in a horrible way to update my QML, before a better and much more cleaner solution was suggested by @SGaist. As it turned out, I just needed to read the Qt docs better, as the solution was there all along.

        1 Reply Last reply
        1
        • P Offline
          P Offline
          Philomath-Qt
          wrote on last edited by
          #3

          Hi @Diracsbracket and thank you for your answer.
          I was working on another but similar approach Exposing Attributes of C++ Types to QML , i was inspired by a stackoverflow post, but always get to a very common error message undefined reference to "vtable for Worker"
          as soon as i add

          QQuickView view;
              Worker msg;
              view.engine()->rootContext()->setContextProperty("msg", &msg);
              view.setSource(QUrl::fromLocalFile("MyItem.qml"));
              view.show();
          

          to my thread.
          I'm trying for hours to fix it, but none of the suggestions online helped.
          I wanted to create a QObject in the one thread, my *.hpp file and then read the properties from my *.qml file

          I will try to use your approach and hope i won't encounter the same problem.

          1 Reply Last reply
          0
          • P Offline
            P Offline
            Philomath-Qt
            wrote on last edited by Philomath-Qt
            #4

            Hi there,
            i found an utterly easy solution to exercise everyhting with using a QObject, wihtout having to use QThread.
            In my main.cpp started i start my GUI after the separat runtime using std::thread.
            I created a QObject in a .hpp and .cpp class with a slot and a signal. I had to add

            QQmlContext* context = engine.rootContext();
             context->setContextProperty("signalData", separat_process.pointer);
             engine.load(QUrl("qrc:/qml/dashboard.qml"));
            

            to my main to connect my GUI to the Object. In the separat_process i use the slots of the QObject which triggers signals.
            Then i had to add

                Connections {
                    target: signalData
                    function onXYZ(abc) {
                        //something happens
                    }
                    function onXYZ(abc) {
                     //something else happens
                    }
                }
            

            to my GUI Item.

            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