QMainWindow::statusBar() no object
According to the Qt documentation you can call
from anywhere in the application.
However, I get an error: no object, so I have to pass the QMainWindow object as an argument wherever I want to apply the statusbar.
What is wrong?
There is nothing wrong. QMainWindow::statusBar() is just not a static function. Besides, most widgets provide status tips. Have a look at the QWidget source to get an idea on how status tips are handled.
You can have multiple mainwindows (and statusbars), so a static statusBar() wouldn't work.
The syntax : QMainWidnow::statusBar()->showMessage is only available for static method, and QMainWidnow::statusBar() is not a static method.
You don't really need to pass the QMainWindow object as an argument, :
-> just pass a reference / pointer to the QStatusBar,
-> use the signal / slot mechanism as QStatusBar::showMessage is a slot...
I think that using signal/slot mechanism will be good here. Something like slot that actually does the statusbar stuff in your mainWindow and connections with all objects from which you need to change statusbar.
Also if you have only one mainwindow you can make it singleton and happily use statusBar(). For example, you have MyMainWindow class inherited from QMainWindow and have getInstance() in it, returning actual instance of your main window. So you can just use @MyMainWindow::getInstance()->statusBar()->showMessage()@