[Qt-interest] unappologetic app crash if statusbar used outside of QMainWindow | example provided
Malyushytsky, Alex
alex at wai.com
Thu Mar 25 23:09:23 CET 2010
Debugger is your friend.
Also I would recommend you to revise design of your classes.
At the first glance it should not be working as is without Status bar.
How many HomeWindow/ CentralPage instances are created?
Lets look:
1 .HomeWindow homeWin("W00+!"); // constructor of HomeWindow is called
// inside HomeWindow constructor new CentralPage is instantiated:
2. CentralPage *centralPageWidget = new CentralPage("test", this); // Since is derived from CentralPage, HomeWindow constructor will be called (HomeWindow instance 2)
// when HomeWindow instance 2 is constructed it will call line above again.
Process will never end. I don't think that is what you wanted.
Regards,
Alex
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of S. Aguinaga
Sent: Thursday, March 25, 2010 12:29 PM
To: Qt Interest
Subject: [Qt-interest] unappologetic app crash if statusbar used outside of QMainWindow | example provided
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...");
}
---------------------------------------------------------------------------------------------------
Weidlinger Associates, Inc. made the following annotations.
"This message and any attachments are solely for the intended recipient and may contain confidential or privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you."
"Please consider our environment before printing this email."
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100325/1ea1eeae/attachment.html
More information about the Qt-interest-old
mailing list