PDA

View Full Version : Subclass QStatusBar



1111
20th February 2009, 09:17
Hello all,

I have main window and I would like to create my own status bar for this window. So the obvious way of doing it is to subclass QStatusBar and create my own class base on that.

So I have a simple class

class MyStatusBar : public QStatusBar
{
// constructor and destructor here
};

Then in MyMainWindow constructor I set status bar like this

this->setStatusBar(myStatusBar);
However, if I start application I get following error

undefined symbol: _ZN10QStatusBar9showEventEP10QShowEvent

My question is :)
Is it possible to subclass QStatusBar? There is nothing about it in Qt manuals. If yes, should I implement some virtual functions, because it looks like application cannot find function body (or maybe I'm wrong).

spirit
20th February 2009, 09:26
you can subclass QStatusBar


#include <QMainWindow>
#include <QStatusBar>

class MyStatusBar : public QStatusBar
{
public:
MyStatusBar(QWidget *parent = 0) : QStatusBar(parent) {}
};

class Test: public QMainWindow
{
public:
Test(QWidget *parent = 0);
};
...
Test::Test(QWidget *parent)
: QMainWindow(parent)
{
setStatusBar(new MyStatusBar);
}

works fine. could you show compilable example?

1111
20th February 2009, 10:14
Hmmm...it looks like I have some internal problem.:crying: Because simple example works fine.