Why is this error: reference to ‘statusBar’ is ambiguous.. coming? Is this a bug?

10,393

Solution 1

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

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

Solution 2

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.

Solution 3

I also read that book and had the same problem. The decision is:

  1. invoke the method QMainWindow::statusBar()
    QMainWindow::statusBar()->showMessage(tr("File successfully loaded."), 3000);

  2. or use a pointer *statusBar from Ui_MainWindow
    Ui_MainWindow::statusBar->showMessage(tr("File successfully loaded."), 3000);

Share:
10,393
shadyabhi
Author by

shadyabhi

Linux Geek, Foodie, Biker!

Updated on June 05, 2022

Comments

  • shadyabhi
    shadyabhi almost 2 years

    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??