[Qt-interest] unappologetic app crash if statusbar used outside of QMainWindow | example provided
S. Aguinaga
sa_jr at yahoo.com
Thu Mar 25 20:29:19 CET 2010
Hello Fellows,
I have started using the Qt example layout "borderlayout", where I create North Central and South panels.
I needed a statusBar so I simply added a qlabel to the South widget, but when I 'setText' nothing happens, when this is being called from the Central Widget. So I changed things around where I created a QStatusBar object in the mainwindow, and then tried to access it from the Central Widget.
I even inherited the mainwindow (which I call the Home Window) into the Central Widget.
And if I try to access the status bar, the whole app crashes. I created a simple project to demonstrate the issue. My question is: How do I access a statusbar object from a centralWidget class that is derived from QWidget?
Let me know if you'd like me to post the source files for download.
// Salvador
// Northwestern University
=== main.cpp ==
#include <QApplication>
#include "homewindow.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
app.setOrganizationName("Trolltech");
app.setApplicationName("Application Example");
HomeWindow homeWin("W00+!");
homeWin.show();
return app.exec();
}
==== homewindow.h =====
#include <QtGui>
#include <QWidget>
#include <QStatusBar>
#include "borderlayout.h"
class HomeWindow;
QT_BEGIN_NAMESPACE
class QAction;
class QMenu;
class QPlainTextEdit;
QT_END_NAMESPACE
//! [0]
class HomeWindow : public QWidget
{
Q_OBJECT
public:
HomeWindow(){};
HomeWindow( const QString, QWidget *parent=0);
QStatusBar *southWidget;
BorderLayout *layout;
};
class CentralPage : public HomeWindow
{
Q_OBJECT
public:
CentralPage(const QString &, QWidget *parent = 0);
public slots:
void btnSlot();
};
===== homewindow.cpp =====
#include <QtGui>
#include "borderlayout.h"
#include "homewindow.h"
HomeWindow::HomeWindow(const QString xperimenter, QWidget *parent )
: QWidget(parent)
{
// central Widget
CentralPage *centralPageWidget = new CentralPage("test", this);
// South Widget //
southWidget = new QStatusBar(this);
layout = new BorderLayout;
layout->addWidget( centralPageWidget, BorderLayout::Center);
layout->addWidget( southWidget, BorderLayout::South);
setLayout(layout);
setWindowTitle(tr("Home Window"));
setMinimumSize(1000*0.7,618*0.7);
southWidget->showMessage("Ready...");
}
CentralPage::CentralPage( const QString &expID, QWidget *parent)
: HomeWindow()
{
QPushButton *someBtn = new QPushButton(tr("Click me"));
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget( someBtn );
setLayout( layout );
connect(someBtn, SIGNAL( clicked() ), this, SLOT( btnSlot()));
}
void CentralPage::btnSlot()
{
southWidget->showMessage("button clicked...");
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100325/4c365480/attachment.html
More information about the Qt-interest-old
mailing list