Results 1 to 3 of 3

Thread: QMessageBox closes entire application

  1. #1
    Join Date
    Sep 2009
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QMessageBox closes entire application

    hi all, I need some help please...
    I can't figure out why when I open a QMessageBox in my application and then press a button on it, the whole application quits...

    my code:
    Qt Code:
    1. // creating a main menubar to trigger the message box
    2. void MyClass::createMainMenu (QMainWindow* parent)
    3. {
    4.  
    5. QAction* errWin = new QAction("Display Error", this);
    6.  
    7.  
    8. QMenu* fileM = new QMenu(parent);
    9.  
    10. fileM = menuBar()->addMenu("&File");
    11. fileM->addAction(errWin);
    12.  
    13. connect(errWin, SIGNAL(triggered()), this, SLOT(ErrAlert()));
    14.  
    15. };
    To copy to clipboard, switch view to plain text mode 
    ------------

    Qt Code:
    1. // Message Box
    2. void ErrAlert() {
    3. QMessageBox* msgBox = new QMessageBox("MSG Title" , "MSG Content", QMessageBox::Information,
    4. QMessageBox::Yes, QMessageBox::No, QMessageBox::Cancel | QMessageBox::Escape);
    5. msgBox->exec();
    6. delete msgBox;
    7.  
    8.  
    9. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. // main.cpp
    2. QMainWindow* mainW = new QMainWindow;
    3.  
    4. MyClass* bkm = new MyClass(mainW);
    5. bkm->show();
    To copy to clipboard, switch view to plain text mode 


    ok so the problem is that when I trigger the ErrAlert func. it works, by opening me the QMessageBox specified, but when I close it, it closes me the entire application... why is that happening, and how can I omit it?
    please someone...
    Last edited by Leoha_Zveri; 19th September 2009 at 11:45.

  2. #2
    Join Date
    Mar 2007
    Location
    Germany
    Posts
    229
    Thanks
    2
    Thanked 29 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QMessageBox closes entire application

    1st. Use [code] tags when posting code here .
    2nd. Perhaps it helps when you don't create the message box on the heap using new, but create it directly on the stack. The message box is only used inside the slot ErrAlert(), so there is no need to create it with new.

  3. The following user says thank you to Boron for this useful post:

    Leoha_Zveri (19th September 2009)

  4. #3
    Join Date
    Sep 2009
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QMessageBox closes entire application

    thanks a lot!!!!!!!!!!!!! it worked

Similar Threads

  1. Replies: 6
    Last Post: 5th August 2009, 10:40
  2. Deploying Qt 4.5.1 Application on RHEL 5.. Pls Help
    By swamyonline in forum Installation and Deployment
    Replies: 0
    Last Post: 28th June 2009, 11:43
  3. About QMessageBox close my tray application
    By Doles in forum Qt Programming
    Replies: 2
    Last Post: 19th July 2008, 21:27
  4. dll + application
    By fpujol in forum Qt Programming
    Replies: 11
    Last Post: 15th April 2007, 18:37

Tags for this Thread

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.