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. Multiples Connections in QML
Forum Updated to NodeBB v4.3 + New Features

Multiples Connections in QML

Scheduled Pinned Locked Moved QML and Qt Quick
jsonqmlqtquickconnectionsc++qnetworkaccessmqnetworkreply
2 Posts 2 Posters 3.1k Views 2 Watching
  • 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.
  • A Offline
    A Offline
    Antonio Ortiz
    wrote on last edited by
    #1

    Hi, I'm trying to receive two jsonArrays from two different endpoints to build a list in QML with a Listview.
    The json contains the same data structure, so I save the data in a single C++ object. In order to do that, I request the json from the first endpoint and then wait for the signal replyStatusChanged() to call a javascript controller that saves the json's content in the C++ object, and then repeat the process for the second one.
    When I do this I encountered that the jsons arrives in any order an I need to wait for the first data to be fully loaded in the object before the writing of the second set of data starts.

    How can I check if the data of the second endpoint has been received and the data of the first endpoint has been written?. I was thinking on using two signals but I don't know how to do it.

    The classes

    Class a : public QObject
    {
         ...
         Q_INVOKABLE void get ();
         Q_INVOKABLE QJsonArray getJsonArray();
          signals:
         void replyStatusChanged();
    }
    
     Class b : public QObject
     {
          //Contains the data
     }     
    

    the main fucntion

     int main(int argc, char *argv[])
     {
          a endpoint1;
          a endpoint2;
          b container;
    
          engine.rootContext()->setContextProperty("endpoint1", &endpoint1);
          engine.rootContext()->setContextProperty("endpoint2", &endpoint2);
          engine.rootContext()->setContextProperty("container", &container);
          ...
    
          return 0;
    }
    

    In the QML file

    Connections
    {
            target: endpoint1
            onReplyStatusChanged: controller.setData1()
    }
    
    Connections
    {
        target: endpoint2
        onReplyStatusChanged: controller.setData2()
    }
    
    1 Reply Last reply
    0
    • benlauB Offline
      benlauB Offline
      benlau
      Qt Champions 2016
      wrote on last edited by
      #2

      Not quite understand your question.. Generally speaking, Javascript application use a Promise object for deferred and asynchronous operation. For example , do something when two or more asynchronous operations completed (in any order).

      Qt do not bundle any Promise implementation by default. You could get a one from my github repo:

      benlau/quickpromise

      Example

      
      Promise {
        resolveWhen: Q.all([endpoint1. onReplyStatusChanged,endpoint2. onReplyStatusChanged]);
        onFulfilled: { // It will be triggered only if both of the endpoint emitted the signal
          controller.setData1();
          controller.setData2();
       }
      }
      
      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