Unsolved Status messages from different class
-
I have developed a desktop application. Different modules forms are opened in the centralwidget area of mainwindow.
I want to show the status messages from different module in a popup area or status bar area in the mainwinodw. how can i acheive the task ? -
Hi @BinuJanardhanan,
you can emit signals from the subwidgets and evalute them in a slot in your main window.
-
@aha_1980
thanks for your replyThat quite complex. I have a number of classes. so that much signal slot leads to complications. So need a better solution.
-
@BinuJanardhanan Did you know that you can connect multiple signals to the same slot? and other way round, one signal can connect to many slots.
the system is very flexible.
-
@aha_1980
Yes, i know sir.
Even though I have to write more connect and signal emit. -
Hi
There is no better way as if you are not using
signals and slot, then you need a pointer to the actual statusbar to set text
and that is even worse.also, its
signals:
showStatusMessage(const QString & message, int timeout = 0);in each of the modules. pr class.
Then in mainwindow where you construct the modules.
then connect the objects
showStatusMessage
to
void QStatusBar::showMessage(const QString & message, int timeout = 0)How many classes do you have?
-
Hi and Welcome!
This is purely a matter of design. There should be a well defined system for handling the messages (statii) that you wish to display. The classes should only be concerned with that interface. Your client should only be concerned with processing that interface.
The first questions that come to mind are: Are your modules forked processes (*nix), threads, or using QProcess? This makes all the difference in the world on how to handle things.
There are patterns you can use. One I have used is making my qApp act like a router with a defined signal that my main window can connect its slot to and then each module can attach its corresponding signal to. This forwards the signal to the main window but assumes you have a common interface and a single process with a single or multiple threads but abstracts the user interface from the classes.
Another, and very flexible method, that works for single process or multiple processes is using 0MQ to send messages around. Your main client application will have the handler and can then parse the messages as they come in and display them accordingly. Again, it is all in the design. What makes this so flexible is 0MQ is a messaging system. You can develop your patterns and have them connect directly or through a routing system, move across networks, use UDP, TCP, pipes, etc.
Again, I strongly suggest you map out what messages and how you want them to communicate. So you could know, this latter technique is actually used in aircraft systems for decades between 1553 and now Ethernet and to a smaller scale extent using CANbus networks in marine, automotive, and industrial applications.
Enjoy!