Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[Solved]Getting error "statusBar was not declared in this scope"?!



  • Hello

    I would like to use statusBar() in my application to show some information ,I tried first to implement some examples to understand the concept of the statusBar ,however I don't know why I get this error "statusBar was not declared in this scope"?!


  • Lifetime Qt Champion

    Hi,

    Can you show the code that is failing ?



  • Since You haven't told what is statusBar exactly. I am assuming that you are using statusBar() function.

    then please check that have you declared statusBar() method in header file correctly or not.



  • I am tryieng to implement what I need from this example

    @#include <QGridLayout>
    #include <QLabel>
    #include <QFrame>
    #include <QStatusBar>
    #include "statusbar.h"

    Statusbar::Statusbar(QWidget *parent)
    : QMainWindow(parent)
    {
    QFrame *frame = new QFrame(this);
    setCentralWidget(frame);

    ok = new QPushButton("OK", frame);
    ok->move(20, 50);

    apply = new QPushButton("Apply", frame);
    apply->move(120, 50);

    statusBar();

    connect(ok, SIGNAL(clicked()), this, SLOT(OnOkPressed()));
    connect(apply, SIGNAL(clicked()), this, SLOT(OnApplyPressed()));
    }

    void Statusbar::OnOkPressed()
    {
    statusBar()->showMessage("OK button pressed", 2000);
    }

    void Statusbar::OnApplyPressed()
    {
    statusBar()->showMessage("Apply button pressed", 2000);
    }@
    [quote author="SGaist" date="1405505571"]Hi,

    And when I compile the code I get this error

    Can you show the code that is failing ?[/quote]


  • Lifetime Qt Champion

    The name of your widget is not really a good idea, MainWindow would be more meaningful and less error prone.

    Do you have by any chance a member variable that's name statusBar ?



  • In the constructor , you are calling statusBar() method. But it is not defined in the class. I think that's why it is showing this error.


  • Lifetime Qt Champion

    ankursaxena It is: "QMainWindow::statusBar()":http://qt-project.org/doc/qt-5/qmainwindow.html#statusBar



  • Ohk Gaist sir. Now i got it.

    I have run this code. and It is working perfectly.



  • Yes the code is work when I create a project with base class QMainWindow ,

    however when I implement that on my project which the base class is QDialog the error is appear ..

    [quote author="SGaist" date="1405510932"]ankursaxena It is: "QMainWindow::statusBar()":http://qt-project.org/doc/qt-5/qmainwindow.html#statusBar[/quote]



  • Because statusBar() is defined in the QMainWindow class and I searched and found that it is not defined in QDialog.



  • thanks all for your replies ..
    I find a solution Yes as you said statusBar() is defined in QMainWindow class and it is not define in QDialog class.

    what I did is adding status bar manually using a layout

    @ QLayout *l = new QVBoxLayout(ui->frame);

             QStatusBar *bar = new QStatusBar;
             l->addWidget(bar);
    

    @
    [quote author="ankursaxena" date="1405575930"]Because statusBar() is defined in the QMainWindow class and I searched and found that it is not defined in QDialog.[/quote]


  • Lifetime Qt Champion

    That's the kind of "minor" detail that you should mention from start


Log in to reply