PDA

View Full Version : QMessageBox closes entire application



Leoha_Zveri
19th September 2009, 09:38
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:


// creating a main menubar to trigger the message box
void MyClass::createMainMenu (QMainWindow* parent)
{

QAction* errWin = new QAction("Display Error", this);


QMenu* fileM = new QMenu(parent);

fileM = menuBar()->addMenu("&File");
fileM->addAction(errWin);

connect(errWin, SIGNAL(triggered()), this, SLOT(ErrAlert()));

};

------------


// Message Box
void ErrAlert() {
QMessageBox* msgBox = new QMessageBox("MSG Title" , "MSG Content", QMessageBox::Information,
QMessageBox::Yes, QMessageBox::No, QMessageBox::Cancel | QMessageBox::Escape);
msgBox->exec();
delete msgBox;


};


// main.cpp
QMainWindow* mainW = new QMainWindow;

MyClass* bkm = new MyClass(mainW);
bkm->show();


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...

Boron
19th September 2009, 11:27
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.

Leoha_Zveri
19th September 2009, 11:44
thanks a lot!!!!!!!!!!!!! it worked