Results 1 to 3 of 3

Thread: QMessageBox kill program if parent QWidget is hidden??

  1. #1
    Join Date
    Mar 2009
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QMessageBox kill program if parent QWidget is hidden??

    QMessagebox kill program if parent QWidget is hidden. (Qt 4.6)

    main.cpp
    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include "widget.h"
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7. Widget w;
    8. w.show();
    9. //w.hide(); // #1
    10. return a.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 

    widget.cpp
    Qt Code:
    1. #include "widget.h"
    2. #include <QApplication>
    3. #include <QAction>
    4. #include <QSystemTrayIcon>
    5. #include <QMenu>
    6.  
    7. Widget::Widget(QWidget *parent)
    8. : QWidget(parent)
    9. {
    10. QAction *aboutQtAction = new QAction(tr("&About Qt"), this);
    11. QObject::connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
    12. QMenu *trayMenu = new QMenu(this);
    13. trayMenu->addAction(aboutQtAction);
    14. QSystemTrayIcon *trayIcon = new QSystemTrayIcon(this);
    15. trayIcon->setContextMenu(trayMenu);
    16. trayIcon->show();
    17.  
    18. //setWindowFlags(Qt::Desktop); // #2
    19. }
    To copy to clipboard, switch view to plain text mode 

    widget.h
    Qt Code:
    1. #ifndef WIDGET_H
    2. #define WIDGET_H
    3.  
    4. #include <QtGui/QWidget>
    5.  
    6. class Widget : public QWidget
    7. {
    8. Q_OBJECT
    9.  
    10. public:
    11. Widget(QWidget *parent = 0);
    12. ~Widget();
    13. };
    14.  
    15. #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?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QMessageBox kill program if parent QWidget is hidden??

    Quote Originally Posted by John Smith View Post
    Why my program crashes and how can I fix it?
    Don't set your widget type to Qt:esktop. You should never set this flag yourself.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QMessageBox kill program if parent QWidget is hidden??

    Quote Originally Posted by John Smith View Post
    Why my program crashes and how can I fix it?
    Don't set your widget type to Qt::Desktop. You should never set this flag yourself.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Application crasches due to QMessageBox if hidden
    By dobedidoo in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2012, 16:42
  2. Promoting the parent QWidget of a QWidget form
    By extrakun in forum Qt Tools
    Replies: 6
    Last Post: 16th April 2010, 15:19
  3. qwidget how to set visible/hidden ?
    By ricky in forum Newbie
    Replies: 4
    Last Post: 12th August 2009, 09:07
  4. QMainWindow or QWidget start hidden?
    By marf in forum Qt Programming
    Replies: 2
    Last Post: 3rd December 2008, 18:23
  5. how to kill parent widget?
    By mahe2310 in forum Qt Programming
    Replies: 3
    Last Post: 23rd March 2006, 13:56

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.