IPC between Python backend to a QML GUI
-
Hi,
I am using Qt Creator to create a gui that shows ambient air temperature and speed of a car to a touchscreen working on Raspberry Pi 4. The python backend connects to the vehicle and gets the data successfuly, and keeps them in string variables. How can I use Qt's interprocess communication methods to change the text on the gui when a the data in python is updated? Can you provide a simple code or a tutorial on how to do this?
Thank You -
Hi and welcome to devnet,
Since you already are working with Python, why note use PySide2 or 6 to do the GUI part ?
-
What exact issue did you got ?
-
On the Application window, the value that was passed from the python is not shown. Instead I see only "..." maybe something else is writing after that but cannot read it exactly. The qml part cannot load the python variable is what I am guessing but I could not manage to get it working
-
Something is not clear: are you writing your application in Python ?
-
No. I created the app from QT creator using QML. On the GUI that uses the qt quick controls, I have a text box. The content of the text box should be updated with a new value, and the value should come from a seperate python script. On python I create the needed data and keep them as string variables. On QML, I need to access the value of those python strings to update the value with them. For example,
It says "Temperature: BLABLA" on the GUI, and the temperature data is stored in a seperate python script. How can I simply reach those values that are on the python and present them on qml GUI? -
@mertb See here: https://doc.qt.io/qt-5/ipc.html
You can't do IPC with QML as far as I know, so you will need to write also C++ code which communicates with the Python process over IPC and provides the data to QML (https://doc.qt.io/qt-5/qtqml-cppintegration-topic.html). -
@mertb said in IPC between Python backend to a QML GUI:
the temperature data is stored in a seperate python script.
This concept is not clear. Do you mean your Python scripts is responsible for reading the temperature from some device ?
-
In that case why not use something like MQTT to publish the device data ?
On the Qt side use the QtMqtt module to subscribe to it. -
Thanks for your replies and interest.
MQTT Sounds like a very nice and robust solution, but my project requires using a wired usb connection that can be very easily handled by a library on python. Therefore, I need to keep using python and usb connection. jsulm's advice on using C++ turned out be really easy to implement, so I will probaby do so. I am planning to make python script and C++ that connects via an IPC method. For now I can send out static messages from C++ to my GUI following some tutorials on QT's Youtube.Thanks and have a good day!
-
If you have now everything in C++, why do you even need IPC ? You can do everything within the same application.