[Qt-interest] statusBar()

Malyushytsky, Alex alex at wai.com
Fri Mar 27 03:24:39 CET 2009


Denton,

In previous his posts Sujan demonstrated ability to assign values to global variables. He could do this to the pointer of statusBar or even his main window, if my conclusion was wrong. So I believe any attempt to help him in this situation does more harm than good.

But since you missed one of the method I would consider preferrable,
I will describe QT way to do it.

Add to each class which should show message on status bar signal:
showMessage ( const QString & message, int timeout = 0 );
emit this signal with appropriate string to display message.

When you create instance of such class connect this signal to the slot
showMessage ( const QString & message, int timeout = 0 ) of statusBar().

That is it. This method allows you to hide details of implementation.
Also if such class is a child of QMainWindow you will have all the pointers at the time you need to do connection, which means you don't need to store them anywhere or make any assumptions about widget parent.

Regards,

Alex


-----Original Message-----
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Denton Vis
Sent: Thursday, March 26, 2009 5:40 PM
To: qt-interest at trolltech.com
Subject: Re: [Qt-interest] statusBar()

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."

_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest

"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."




More information about the Qt-interest-old mailing list