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. What signal to use for QT to update data pulled in from libcurl

What signal to use for QT to update data pulled in from libcurl

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 273 Views 1 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.
  • L Offline
    L Offline
    Laner107
    wrote on last edited by
    #1

    Hello, I am having trouble figuring out how to have my program refresh in the background without the user having to click anything. Currently I use libcurl to pull json data from IEX Cloud API(which gives me stock information). I then have that data read in just simply using a for loop(basic I know). But after the for loop is done the user has to search again for new points to be plotted in my QtChart. What is the best way to have the program always be refreshing the json data looking to see if more data has been updated on it and then plot it? I know the API I use says we can use SSE or WebSockets using REST but im having trouble figuring either out so a push in the right direction might help. Below is also my current code for how I read in the data.

    //Retrieves json format of data
        Json::Value chartData = IEX::stocks::chartYtd(symbol_std);
    
        //Size of json
        int n = chartData.size();
    
        //Stores x and y values
        QVector<double> time(n), closePrice(n);
    
        //Intialize first vector to first values
        closePrice[0] = chartData[0]["close"].asDouble();
    
        //Finds max and min for range
        float maxAvg = closePrice[0];
        float minAvg = closePrice[0];
    
    
        //Reads in data from json(historical data 1 day delayed)
        for(int i = 1; i < n; i++)
        {
            time[i] = i + 1;
            closePrice[i] = (chartData[i]["close"].asDouble());
    
            if((closePrice[i] == 0) && (time[i] != chartData.size() - 1))
            {
                closePrice[i] = closePrice[i-1];
            }
    
            if(closePrice[i] > maxAvg)
            {
                maxAvg = closePrice[i];
            }
    
            else if(closePrice[i] < minAvg)
            {
                minAvg = closePrice[i];
            }
        }
    
    Pablo J. RoginaP 1 Reply Last reply
    0
    • L Laner107

      Hello, I am having trouble figuring out how to have my program refresh in the background without the user having to click anything. Currently I use libcurl to pull json data from IEX Cloud API(which gives me stock information). I then have that data read in just simply using a for loop(basic I know). But after the for loop is done the user has to search again for new points to be plotted in my QtChart. What is the best way to have the program always be refreshing the json data looking to see if more data has been updated on it and then plot it? I know the API I use says we can use SSE or WebSockets using REST but im having trouble figuring either out so a push in the right direction might help. Below is also my current code for how I read in the data.

      //Retrieves json format of data
          Json::Value chartData = IEX::stocks::chartYtd(symbol_std);
      
          //Size of json
          int n = chartData.size();
      
          //Stores x and y values
          QVector<double> time(n), closePrice(n);
      
          //Intialize first vector to first values
          closePrice[0] = chartData[0]["close"].asDouble();
      
          //Finds max and min for range
          float maxAvg = closePrice[0];
          float minAvg = closePrice[0];
      
      
          //Reads in data from json(historical data 1 day delayed)
          for(int i = 1; i < n; i++)
          {
              time[i] = i + 1;
              closePrice[i] = (chartData[i]["close"].asDouble());
      
              if((closePrice[i] == 0) && (time[i] != chartData.size() - 1))
              {
                  closePrice[i] = closePrice[i-1];
              }
      
              if(closePrice[i] > maxAvg)
              {
                  maxAvg = closePrice[i];
              }
      
              else if(closePrice[i] < minAvg)
              {
                  minAvg = closePrice[i];
              }
          }
      
      Pablo J. RoginaP Offline
      Pablo J. RoginaP Offline
      Pablo J. Rogina
      wrote on last edited by Pablo J. Rogina
      #2

      @Laner107 said in What signal to use for QT to update data pulled in from libcurl:

      But after the for loop is done

      Given that "your loop" is part of a class containing the Q_OBJECT macro, you can emit a signal to let the world (other components of your app) that the JSON processing is done, and a new search can start again.

      You can see in the link I posted a brief code snippet for the definition of a class capable of emitting a signal, so later on in your code you can do:

      MyClass::processJson() {
          the_mighty_loop;
          emit stocksProcessingDone();
      }
      

      and then you need to properly wire your signal to some slot...

      Upvote the answer(s) that helped you solve the issue
      Use "Topic Tools" button to mark your post as Solved
      Add screenshots via postimage.org
      Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      1
      • L Offline
        L Offline
        Laner107
        wrote on last edited by
        #3

        @Pablo-J-Rogina Okay i appreciate the help!

        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