[Qt-interest] statusBar()

Denton Vis vistapro7 at hotmail.com
Fri Mar 27 15:23:35 CET 2009


Thanks for your insight guys. I too have learned something.

Denton

"Scott Aron Bloom" <Scott.Bloom at sabgroup.com> wrote in message 
news:7DB34253D57D2B47AEB656218FE6AAEF171448 at onshorecs.com...
> Denton.. Alex is absolutely correct...
>
> It was clear from Sujan's post that he did nto read the basic
> documentation on signals and slots nor did he have a basic understanding
> of C++..
>
> And btw...  It is NOT generally a good idea to communicate upwards from
> child to parent in a type specific manner...
>
> Why?
>
> 1) You have now created a child widget that ONLY works with that 1 type
> of parent.  This makes sense for paired child/parent relationships
> (TreeWidget/TreeWidgetItem or QMidArea/QMdiAreaSubWindow) but is a VERY
> VERY poor technique otherwise
> 2) Your child now has 2 other depencencies in this case.  1 on
> QMainWindow and 1 on Qstatusbar.. neither is necessary
> 3) You had to create a local method and another layer of possible buggy
> code (every line of code is a possible bug) to do something you simply
> don't need...
>
> Now.. look at the QStatusBar::showMessage method.. You will notice, that
> it is indeed a slot.  Why is that important?
>
> Well, here is how I would allow my child to set my status... without
> them ever knowing that I am a QMainWIndow, a QDialog or a console going
> to stdout..
>
> MainWIndow::MainWindow(.....)
> {
>    fChildWindow = new childWIndow();
>    connect( fChildWindow, SIGNAL( sigStatusMessage( const QString &,
> int ) ), this, SIGNAL( sigStatusMessage( const QString &, int ) ) )
>    connect( this, SIGNAL( sigStatusMessage( const QString &, int ) ),
> statusBar(), SLOT( showMessage( const QString &, int ) ) )
> }
>
>
> Now.. any one of my children can update my status bar...  and if I
> change to a QDialog or change how I "show the message" they don't care..
> Maybe I add a logging report of every message.. So I add the following
>
>    connect( this, SIGNAL( sigStatusMessage( const QString &, int ) ),
> fLogger, SIGNAL( sigStatusMessage( const QString &, int ) ) )
>
> Now inside my logger, I connect to that signal and do something...
>
>
> Now.. say my MainWindow was 1 of MANY QMainWindows in the application...
> and my custom QApplication had a better way of showing messages...
>    connect( this, SIGNAL( sigStatusMessage( const QString &, int ) ),
> qApp, SIGNAL( sigStatusMessage( const QString &, int ) ) )
>
> BAM...  And my code in my child window never has to change...
>
> Scott
>
>> -----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 




More information about the Qt-interest-old mailing list