QCustomPlot Discussion and Comments

Adding a realtime QCustomPlot to an existing C++ console-based applicationReturn to overview

What would be the best approach to add a realtime QCustomPlot to an existing C++ console-based application?

This existing application is used for audio processing. It processes 64 audio samples every 10 ms. I want to know what is the best approach to visualize these samples in realtime. The information I have seen on using QCustomPlot so far is based on building a new application with Qt at its core, but this is not an option for me. I basically want to integrate a QCustomPlot as a library in my application so that I can feed it the samples and visualize them. The existing application is handling all the real-time requirements and it is very important that the QT functionality does not influence it. Somewhere on the web I read that the class QProcess can be used for this purpose. However, I couldn't find an example of how. I would really appreciate if somebody gives me a hand with this.

This blog contains all the information that is needed (including example code) to implement what I described above. The only remaining task is filling in the "blanks" with the QCustomPlot realtime example code.

https://blog.pramp.com/inter-thread-communication-in-c-futures-promises-vs-sockets-aeebfffd2107

After doing some more progress, I actually reached a problem I could not fix using the approach I posted above and had to look for another solution.

The solution I found is based on these two Stack Overflow posts:

https://stackoverflow.com/questions/22289423/how-to-avoid-qt-app-exec-blocking-main-thread

https://stackoverflow.com/questions/58049601/communicating-with-a-gui-thread-that-is-not-the-main-thread/58050745?noredirect=1#comment102501021_58050745

That is how I managed to integrate a realtime Qt-based GUI to my existing signal processing application.

Hi there, thank you for pointing those very useful links. It makes sense to use signals and slots to communicate with your UI thread. However, I have struggled to implement what these posts are suggesting.

Would you kindly share a minimal example show how I might connect a signal in my main thread to a slot in the UI running in a worker std::thread?

That’s a great question! Adding a realtime QCustomPlot to an existing C++ console-based application can be a bit tricky because console apps don’t natively support GUI elements. One way to approach this is by converting your project into a Qt Widgets application, or by creating a separate QWidget window that handles the QCustomPlot rendering while your console logic continues in the background. You’ll also need to ensure your event loop (QApplication) is running properly, otherwise the GUI won’t refresh in realtime.

Another helpful tip: decouple your data acquisition logic from your plotting logic. For example, use a QTimer to periodically update the plot with new data, rather than tying updates directly to your console output. That way, your plot remains responsive and scalable.

On a side note, when I was working on documentation and academic tasks around similar topics, I found that reliable resources—like college essay writing services—saved me a lot of time in structuring reports and technical explanations. If anyone is interested, here’s one I’ve personally checked out: https://myassignmenthelp.com/college-essay-writing-service.html

Has anyone here integrated QCustomPlot with console-based C++ before? Would love to hear if you used a hybrid approach or went full Qt application.