Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Closing Message Box Terminates Entire Application
I am a Qt newbie. I find that when my app puts up a box of any kind, closing it closes the whole application. I can always remove the X in the upper right and specifically handle any OK buttons, but isn't there a way to make it so that terminating the pop-up doesn't terminate the whole app? Here is an example of my creation of a pop-up:
Pressing either OK or the X at the upper right makes the whole app terminate.
[edit: @ tags added, Eddy]
RazrFalcon last edited by
@QMessageBox::warning(this,tr("System Message"),tr("Some text."),QMessageBox::Ok);@
fluca1978 last edited by
[quote author="BrandonShw" date="1321374808"]I am a Qt newbie. I find that when my app puts up a box of any kind, closing it closes the whole application. [/quote]
That is probably because you don't have anything else in the application. Moreover, as pointed from RazrFalcon, you should use the static methods of QMessageBox to display dialog boxes with messages.
Thanks, but I get:
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/lib/qt/mkspecs/linux-g++ -I. -I/lib/qt/include/QtCore -I/lib/qt/include/QtGui -I/lib/qt/include -I. -I. -o sysTray.o sysTray.cpp
sysTray.cpp: In member function ‘void SysTray::DisplayMessageToUser(std::string)’:
sysTray.cpp:963: error: no matching function for call to ‘QMessageBox::warning(SysTray* const, QString, QString, QMessageBox::StandardButton)’
/lib/qt/include/QtGui/qmessagebox.h:197: note: candidates are: static QMessageBox::StandardButton QMessageBox::warning(QWidget*, const QString&, const QString&, QFlagsQMessageBox::StandardButton, QMessageBox::StandardButton)
/lib/qt/include/QtGui/qmessagebox.h:245: note: static int QMessageBox::warning(QWidget*, const QString&, const QString&, int, int, int)
/lib/qt/include/QtGui/qmessagebox.h:248: note: static int QMessageBox::warning(QWidget*, const QString&, const QString&, const QString&, const QString&, const QString&, int, int)
/lib/qt/include/QtGui/qmessagebox.h:255: note: static int QMessageBox::warning(QWidget*, const QString&, const QString&, QMessageBox::StandardButton, QMessageBox::StandardButton)
make: *** [sysTray.o] Error 1
When I use:
QMessageBox::warning(x,tr("System Message"),tr("Some text."),QMessageBox::Ok);
it compiles, but still exits when I press the OK button.
[edit: please add @ code tags yourself, Eddy]
RazrFalcon last edited by
You must use QWidget instead if SysTray(what is it?!) or 0.
I tried 0 and it compiles, but the program still exits when the message box closes. Normally, this program appears as a system tray icon which one can right click on to get a menu. When a menu item is selected, the program either pops up a window or takes a non-graphical action. In every case up until now, if a window pops up, exiting it causes the whole app to exit. In the past, I have solved this problem by removing the X at the upper right and using my own exit button, which I then handle in my own slot.
SysTray is the class this method belongs to. It is a subclass of QObject.
lgeyer last edited by
Your Qt application ends - as every other C++ application - as soon as the main() function is left. Make sure you've called exec() on your QApplication object as well.
For further assistance I suggest your provide some code which shows this problematic behaviour.
And - please - wrap your code within @-tags so that it is at least somewhat readable.
giesbert last edited by
The problem might be, that no other windiow is currently visible. this means, the quitOnLastWindowClosed flag from QApplication ensures, the event loop is closed.
Settings this property to false could solve your problem, but then you have to handle the end of the event loop on your own.
C0K01 last edited by
@giesbert That helped! Thanks