Important: Please read the Qt Code of Conduct -

UDP client and real-time graphics

  • Hello,

    I am developing a UDP "client" that receives UDP frames every second. From this data (temperature data for this case), the client displays a graph with all the temperature data received since the customer's launch.

    I can receive UD data without any problems thank to this line :


    But, I can't transmit the data to the "Chart::handleTimeout(QByteArray)" function from the "MyUDP::readyRead()" function.

    I tried with this line :


    But, it didn't work.

    And last but not least, I'm a newbie and I have based myself on the following examples:

    Thank you for your help :-) !

  • The syntax is connect(sender,signal,receiver,slot) so:

    • the first argument must be a pointer to the object emitting the signal
    • the second argument must be either a function pointer to the specific signal or the name of the signal in the SIGNAL macro.
    • the third argument must be a pointer to the object the slot should execute on
    • the second argument must be either a function pointer to the specific slot or the name of the slot in the SLOT macro.

    In your case the 3rd argument is wrong, it should be an object and you have to remove Chart:: from the forth argument

  • Ok,

    Here, my "myudp.cpp" file :

    #include "myudp.h"
    #include "chart.h"
    MyUDP::MyUDP(QObject *parent) : 
      socket = new QUdpSocket(this);
      //We need to bind the UDP socket to an address and a port
    void MyUDP::SayHello()      //Just spit out some data
      QByteArray Data;
      Data.append("Hello from UDP land");
      //If you want to broadcast something you send it to your broadcast address
    void MyUDP::readyRead()     //Read something
        QByteArray Buffer;
        //Buffer.append("15 24 15 41 ");
        QHostAddress sender;
        quint16 senderPort;
        qInfo() << "bufferData=" <<;
        emit dataReady(;

    And here, my "main.cpp" file :

    #include "chart.h"
    #include "myudp.h"
    #include <QtCharts/QChartView>
    #include <QtWidgets/QApplication>
    #include <QtWidgets/QMainWindow>
    int main(int argc, char *argv[])
        QApplication a(argc, argv);
        MyUDP server;
        QMainWindow window;
        Chart *chart = new Chart;
        chart->setTitle("Mesures de températures");
        QChartView chartView(chart);
        window.resize(400, 300);;
        return a.exec();

    The line :


    in the "myudp.cpp" file contain an error. The third argument isn't recognize. Because "chart" is declare in "main.cpp" file.

  • Lifetime Qt Champion

    @dfvgergver It would be better to do the connect in main.cpp. This way your MyUDP class does not have to know anything about any charts:


  • Alleluya !

    It's work ! But like this :


    Thank you very much !

Log in to reply