#include <QtGui>
{
Q_OBJECT
public:
{
connect(this, SIGNAL(clicked()), this, SLOT(mySlot()));
}
private slots:
void mySlot()
{
widget->setAttribute(Qt::WA_DeleteOnClose);
// From docs: "By default this attribute is set for all widgets except
// transient windows such as splash screens, tool windows, and popup menus."
// Clear Qt::WA_QuitOnClose attribute. (Notice the difference if you comment this line out..)
widget->setAttribute(Qt::WA_QuitOnClose, false);
widget->show();
}
};
int main(int argc, char *argv[])
{
MyButton* w = new MyButton;
w->show();
a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
return a.exec();
}
#include "main.moc"
#include <QtGui>
class MyButton: public QPushButton
{
Q_OBJECT
public:
MyButton(QWidget* parent = 0) : QPushButton("Test", parent)
{
connect(this, SIGNAL(clicked()), this, SLOT(mySlot()));
}
private slots:
void mySlot()
{
QWidget* widget = new QWidget(this, Qt::Window);
widget->setAttribute(Qt::WA_DeleteOnClose);
// From docs: "By default this attribute is set for all widgets except
// transient windows such as splash screens, tool windows, and popup menus."
// Clear Qt::WA_QuitOnClose attribute. (Notice the difference if you comment this line out..)
widget->setAttribute(Qt::WA_QuitOnClose, false);
widget->show();
}
};
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MyButton* w = new MyButton;
w->show();
a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
return a.exec();
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
Bookmarks