Qt Network Plot using QCustomPlot & Python

Qt is a really powerful cross-platform GUI application. There are lot of internal features that you can use to create awesome applications. You can also use thousands of open-source third party libraries to improve your application drastically.

GUI

In this project we will be using QCustomPlot to plot our data in Qt. QCustomPlot is a Qt C++ widget for plotting and data visualization.

Link: https://www.qcustomplot.com/

In this project we will create a simple GUI which will plot our real time data coming on TCP. The graph will be interactive and can be descaled easily. Even the plot style can be changed according to our need.

GitHub link: https://github.com/harshmittal2210/Qt-Network-Plot

How to use QCustomPlot in Qt?

It is fairly very easy to use QCustomPlot in Qt. In the following video I have shown how to set up the project and organize your source and header files and then plot basic data.

Part 1

You can also refer the official documentation of QCustomPlot from here to get basic idea.

Add Push Buttons

In the above section we have seen how to add plot in Qt. Now we will add push buttons to plot, clear data and close the program.

Change Plotting Style

QCustomPlot also gives us different plotting features. In the following video I have shown how to change the plotting style of data coming in real time.

Create Server accepting multiple connections

Creating server can be challenging in different OS, but Qt makes it really easy. In the following video I have used multi-threading to create server which enables multiple clients to send data at same time.

Create Python Client and send JSON Data

Creating client is very straightforward. In this video I have shown how you can send continuously data in JSON format to a server.

Use SIGNAL & SLOTS to send data between threads

In this section I have shown how you can send data from a thread to main window for plotting using multiple Signal and Slots.

Method 1:

We will create a server thread to run server independently to accept connection request. This enables GUI to run separately so that it does not hangs.

Method 2:

We will run server on main thread itself. This allows us to decrease number of thread and signals emitted to send data to main window.

I am an Embedded Software Engineer. I am really intrested in the filed of Embedded System, IoT and Machine Learning.