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

Access statisBar from member function



  • Hello QT-world,

    how can I access the statusbar in my mainwindow from any member or nonmember function. I have no clue how do accomplish that. It exceeds my actual knowledge base.
    This is what I have so far:

    QtDemo::QtDemo(QWidget *parent) : QMainWindow(parent)
    {
    QWidget *widget = new QWidget;
    ...
    // set a message into staticBar
    statusBar()->showMessage(any_message);
    ...
    any_function();
    }

    void QtDemo :: any_function()
    {
    QtDemo *n;
    n->statusbar->showMessage(...); // does not work, not that member showMessage() !!
    ...
    }

    Who has the right solution?
    Best wishes
    MatFox


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    @MatFox said in Access statisBar from member function:

    void QtDemo :: any_function()
    {
    QtDemo *n;
    n->statusbar->showMessage(...); // does not work, not that member showMessage() !!
    ...
    }

    Why are you creating n in the first place ?
    Just do the same thing you did in the constructor.



  • Hi SGaist,

    what do you mean? Could you be more specific?
    Do mean QtDemo* n = new ... ; etc.


  • Lifetime Qt Champion

    Well, why are you creating a local pointer to a QtDemo object within a method that is part of QtDemo ?


Log in to reply