[Qt-interest] statusBar()

Denton Vis vistapro7 at hotmail.com
Fri Mar 27 01:40:04 CET 2009


Hi Alex,
I may be wrong but I do not think the problem is with calling methods of a 
class in C++. It may seem obvious later, but when new to Qt, it may not be 
as obvious how to get to the top widget sometimes.

I understand that it has more to do with having a main window and several 
subclasses (widgets) and then getting access to the main window in order to 
update the status during an operation.

Sujan:
It is generally a good idea when creating child widgets of your MainWindow, 
to pass the MainWindow as the parent object. That way, it becomes easy to 
make a call on the parent and update the status. You could create a method

void ChildWidget::updateStatus(const QString & message) {
QObject * parent = mainWindow.parent();
QMainWindow * mainWindow = qobject_cast<QMainWindow*>(parent);
if (mainWindow) // if cast was successful
    mainWindow->statusBar()->showMessage(message, 2000);
return;
}

and then make a call to this method each time you wish to update the status 
on the status Bar.

If you update your status bar message a lot, it may help to create a 
QStatusBar* widget in your child widget and run
the code once to get a pointer to the status bar: like so.
QStatusBar* mStatusBar = mainWindow->statusBar();

then each time you update the status bar, it is only necessary to call 
mStatusBar->showMessage(...)

Hope this helps you out.

"Malyushytsky, Alex" <alex at wai.com> wrote in message 
news:F8145CF983B4DB42855E9BB7F5BE8FCC113ED004 at camail2.wai.com...
> There is no way to help you, until you read and understand basics of  C++.
> Don't take it as offence, this is just a reason why you can't be helped 
> here and you don't get any answer on your second time asked question.
>
> Giving you a solution just encourages you to keep flouding this mailing 
> list with basic C++ question. That makes nothing good even to you.
> Hope you finally will follow people advice. Start with definition of the 
> class and object.
>
> Once you get it, you will find your first way to do what you want.
>
> Regads,
>     Alex
>
>
> ________________________________________
> From: qt-interest-bounces at trolltech.com 
> [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Sujan Dasmahapatra
> Sent: Thursday, March 26, 2009 2:55 AM
> To: qt-interest at trolltech.com
> Subject: [Qt-interest] statusBar()
>
> Dear Friends
> In my prpoject I have many classes and the  main class is "MainWindow" 
> which is derived  from QMainWindow. So I am able to show message in my 
> 'MainWindow' class......How could I show message on the statusBar from any 
> other class. When I am trying to do that its not happening.Plss tell me 
> some idea to show message from other class than MainWindow..
>
> Kind regards,
> LM Glasfiber R&D (India) Pvt. Ltd.
>
> Sujan Dasmahapatra
> Project Engineer - CFD
>
> Telephone: +91 80 66470248
> Mobile:
> E-mail: sdh at lmglasfiber.com
>
>
>
>
> --------------------------------------------------------------
> This e-mail and any attachments are confidential. If you are not the named 
> or intended recipient, please notify the sender immediately and do not 
> disclose the contents to any other person, use it for any purpose or store 
> or copy the information in any medium. Any unauthorized disclosure, use or 
> storage is prohibited and might be unlawful.
>
>
> ---------------------------------------------------------------------------------------------------
> Weidlinger Associates, Inc. made the following annotations.
>
> "This message and any attachments are solely for the intended recipient 
> and may contain confidential or privileged information. If you are not the 
> intended recipient, any disclosure, copying, use, or distribution of the 
> information included in this message and any attachments is prohibited. If 
> you have received this communication in error, please notify us by reply 
> e-mail and immediately and permanently delete this message and any 
> attachments. Thank you."
>
> "Please consider our environment before printing this email." 




More information about the Qt-interest-old mailing list