QMessagebox kill program if parent QWidget is hidden. (Qt 4.6)
main.cpp
#include <QtGui/QApplication>
#include "widget.h"
int main(int argc, char *argv[])
{
Widget w;
w.show();
//w.hide(); // #1
return a.exec();
}
#include <QtGui/QApplication>
#include "widget.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
//w.hide(); // #1
return a.exec();
}
To copy to clipboard, switch view to plain text mode
widget.cpp
#include "widget.h"
#include <QApplication>
#include <QAction>
#include <QSystemTrayIcon>
#include <QMenu>
{
QObject::connect(aboutQtAction,
SIGNAL(triggered
()),
qApp,
SLOT(aboutQt
()));
trayMenu->addAction(aboutQtAction);
trayIcon->setContextMenu(trayMenu);
trayIcon->show();
//setWindowFlags(Qt::Desktop); // #2
}
#include "widget.h"
#include <QApplication>
#include <QAction>
#include <QSystemTrayIcon>
#include <QMenu>
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
QAction *aboutQtAction = new QAction(tr("&About Qt"), this);
QObject::connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
QMenu *trayMenu = new QMenu(this);
trayMenu->addAction(aboutQtAction);
QSystemTrayIcon *trayIcon = new QSystemTrayIcon(this);
trayIcon->setContextMenu(trayMenu);
trayIcon->show();
//setWindowFlags(Qt::Desktop); // #2
}
To copy to clipboard, switch view to plain text mode
widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QtGui/QWidget>
{
Q_OBJECT
public:
~Widget();
};
#endif // WIDGET_H
#ifndef WIDGET_H
#define WIDGET_H
#include <QtGui/QWidget>
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = 0);
~Widget();
};
#endif // WIDGET_H
To copy to clipboard, switch view to plain text mode
If line #1 or #2 uncommented, when I close QMessagebox (aboutQt in this example), my program crashes.
Why my program crashes and how can I fix it?
Bookmarks