views:

231

answers:

2

I created a QMainWindow using QT Designer. As we know, it has statusBar by default.

By default, QT Designer gave its objectname as "statusBar". Now, when I tried to call like:-

statusBar()->showMessage(tr("File successfully loaded."), 3000);

as we have a function with prototype: QStatusBar * QMainWindow::statusBar () const

The Compiler shows the error:-

error: reference to ‘statusBar’ is ambiguous.

error: candidates are: QStatusBar* Ui_MainWindow::statusBar

error: QStatusBar*QMainWindow::statusBar() const

Actually, i was following a book "The Art of Building Qt Applications by DANIEL MOLKENTIN". And I am compiling the same code given in book.

Above code is in mainwindows.cpp and i have included "mainwindow.h" & "ui_mainwindow.h" in it...

Is this a bug in QT4??

+1  A: 

The problem is that QMainWindow extends Ui_MainWindow, which also defines the statusBar method.

Probably this wasn't the case in previous versions of QT.

kgiannakakis
I am a newbie for GUI stuff with just knowledge of basic C++. so have I found a bug?
shadyabhi
No this is normal behaviour and not a bug. Since there are two definitions of statusBar, you need to explicitly select one.
kgiannakakis
+2  A: 

Ask for a specific version of the method statusBar():

Ui_MainWindow::statusBar()->showMessage(tr("File successfully loaded."), 3000);
Martin York
No that will throw an error.. There is no function named statusBar in Ui_MainWindow..Anyways, i think you wrote it in a hurry. It should be QMainWindow::statusBar().....But, the main agenda was, is it a BUG?
shadyabhi
That's not what the error above (in your question) says. Yes it is a BUG in __Your__ code (or the book). But without further context (like the code) it is imposable to narrow it down further.
Martin York