PDA

View Full Version : Communication with multiple MDI widgets



dan3460
8th July 2017, 20:36
Hey guys, i'm new to the forum and fairly new to QT. I have been using it on and off for more than a year and i have came to the following problem that i have not been able to pass.
I have a main window with an MDI are and several child widget that are created in that are. Each one of the widget represent a circuit which I'm monitoring the voltage. The widgets are created by a loop when the main window is initialized. How can i talk to each child?

dan3460
9th July 2017, 00:17
In case anyone is interested. I solved the problem, maybe crude and they maybe other solutions out there but here is how i did it.

The main window updates a data class constantly, i have each of the child widget using a timer reading data from the data class. Works pretty well.

d_stranz
9th July 2017, 21:23
The more Qt way of doing this is to derive the data class from QObject and implement a "dataUpdated()" signal for it. Each time the main window changes the data class, the data class emits this signal.

Every child window has a "dataUpdate()" slot. When the main window creates the child windows, it connects this slot to the data class signal. In the child window slot, you do whatever you do to update the child's display.

No need for timers or anything of the sort. The child windows update themselves only when necessary, not according to some arbitrary timeout signal which might cause them to miss new data (if the timeout is too long) or update themselves unnecessarily (if the timeout is too short).