PDA

View Full Version : slot "return" close my GUI app



Joelito
13th March 2014, 19:09
Hi, I have a slot for qpushbutton:


connect(button1, SIGNAL(clicked()), this, SLOT(handleButtonClicked()));
/* more code */
protected slots:
void handleButtonClicked()
{
qDebug() << "Clicked handler";
/* test if you want to continue the event */
int ret = QMessageBox::question(...);
if (ret != QMessageBox::Yes) {
return; // cancel the propagation?
}
qDebug() << "Glad that you join us";
}

my problem is that when I hit "No", the window closes :(
any ideas?

anda_skoa
13th March 2014, 20:20
my problem is that when I hit "No", the window closes :(

Which has nothing to do with your code.



any ideas?

No. Not enough information to even guess.

Cheers,
_

Joelito
13th March 2014, 20:32
When I hit button in my app (buttton1) there's a QMessageBox with yes and no buttons...if the user hits "no" button in the QMessageBox, the GUI closes. So the expected situation is that after the "no" button the function returns or exits without displaying Glad that you join us

ChrisW67
13th March 2014, 20:40
That is not happening in the code you are showing us. Run your program in your debugger and single step through this slot to find out where it actually "closes", whether that is an abnormal or normal termination, and the actual trigger for it.

sulliwk06
13th March 2014, 20:43
why dont you use a switch statement on the return from the dialog and catch the no response, then try to do something other than return? maybe add a breakpoint and debug it.

Joelito
13th March 2014, 20:47
The debugger is clean:


[New Thread 0xac796b40 (LWP 1368)]
[Thread 0xac796b40 (LWP 1368) exited]
[Inferior 1 (process 1362) exited normally]
(gdb) where
No stack.
(gdb)

ChrisW67
13th March 2014, 22:17
And where did it exit from after the slot call returned?

Joelito
14th March 2014, 14:54
I think I know the problem:

1.- If the GUI is visible the QMessageBox responds as expected and the function returns if I click and the "No" button; the GUI stills active.
2.- But if the GUI is hidden ans I display the QMessageBox, the GUI closes after I click "No".

:-/

anda_skoa
14th March 2014, 15:18
Does it help if you set http://qt-project.org/doc/qt-4.8/qapplication.html#quitOnLastWindowClosed-prop to false?

Cheers,
_

Joelito
15th March 2014, 14:26
Thanks for the tip, @anda_skoa. It did help and also I think QMessageBox needs a valid parent pointer to avoid the application exits.