Important: Please read the Qt Code of Conduct -

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

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

  • @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() {
        emit stocksProcessingDone();

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

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

Log in to reply