Details
-
Bug
-
Resolution: Done
-
P3: Somewhat important
-
4.5.2
-
None
-
-
7f2f38d48b58b6b1ef90198bf2d03422826a5b08
Description
Platform details
Leopard 10.5.8, Intel Mac Pro (8-core Xeon, 4GB RAM)
Steps to reproduce / test case
Note: this bug only appears in conjunction with Qt/OSC configured with the "--cocoa" option. Under the default/carbon build, the correct/expected behavior is observed.
To reproduce:
1) Compile and run the attached example program
2a) You should see two windows open, titled "Window #1" and "Window #2".
2b) Each window has a "Delete This Window" button which causes deleteLater() to be called on the window.
2c) Each window adds a "Quit" menu item to the menu, which calls MyWindow::MyCustomQuit() method. Note that MyCustomQuit() DOES NOT quit the application; rather it only updates the "Hi there" label in the GUI.
3) Click the "Delete This Window" button in Window #1. Window #1 disappears (as expected).
4) Immediately (i.e. without clicking anywhere else first) choose "Quit" from the menu, or press Command-W. Note that the application quits at this point. That is incorrect behavior – the correct/expected behavior is for the label text to update, and the app should NOT quit.
To observe the correct/expected behavior, recompile the app against Qt/4.5.2/OSX/Carbon and re-do the steps above.
More information
// BEGIN main.h
#ifndef main_h
#define main_h
#include <QtGui>
class MyWindow : public QMainWindow
{
Q_OBJECT
public:
MyWindow(const QString & s);
private slots:
void MyCustomQuit();
private:
QLabel * _label;
int _count;
};
#endif
// end main.h
// begin main.cpp
#include "main.h"
MyWindow :: MyWindow(const QString & s) : _count(0)
{
setWindowTitle(s);
QMenu * menu = menuBar()->addMenu(tr("MyProgramMenu"));
menu->addAction("Quit", this, SLOT(MyCustomQuit()));
QWidget * w = new QWidget;
{
QBoxLayout * vbl = new QBoxLayout(QBoxLayout::TopToBottom, w);
QPushButton * p = new QPushButton("Delete This Window");
connect(p, SIGNAL(clicked()), this, SLOT(deleteLater()));
vbl->addWidget(p);
_label = new QLabel("Hi there");
_label->setAlignment(Qt::AlignCenter);
vbl->addWidget(_label);
}
setCentralWidget(w);
}
void MyWindow :: MyCustomQuit()
{
printf("MyCustomQuit is called!\n");
_label->setText(QString("MyCustomQuit called (%1 times)").arg(++_count));
}
int main(int argc, char ** argv)
{
QApplication app(argc, argv);
for (int i=0; i<2; i++)
{
MyWindow * m = new MyWindow(QString("Window #%1").arg(i+1));
m->setGeometry(QRect(50+(i*300), 50, 250, 50));
m->show();
}
return app.exec();
}
// end main.cpp