Closing main window from sub windows
-
I have a main window under which I have placed three different widgets in the form of tabs. I want to close the entire main window when any error happens inside any of the sub windows or widgets placed in the form of tabs. I am unable to figure it out how to do so. Any help will be appreciated
-
@supratik123 So, you don't want to close the whole application?
-
-
@supratik123 Please tell us what you did and what happened.
Saying it "didn't worked out" does not provide enough information to help you... -
@supratik123 what kind of errors to sub windows?
-
@anil_arise My sub windows are getting connected to server using TCP. So if some error occurs in TCP, I want to close the whole application and not proceed further
-
@jsulm Sorry for that. The scenario is I have a main window which is having three tabs which are widgtes. The three widgets are getting connected to three different servers using TCP. Now if error happens in any of the sub windows, I want my application to close entirely and not proceed further
-
@supratik123 Can you please just tell me what did not work with https://doc.qt.io/qt-5/qcoreapplication.html#exit ?
I already understood what you want to do, no need to explain it again... -
@supratik123 Please show the code where you use https://doc.qt.io/qt-5/qcoreapplication.html#exit
How is anybody supposed to help you if you do not provide enough information?! -
try { //invoking the MCIS library using scope pointer member of MCIS static library this->m_libMCIS.reset(new MCIS(m_mcisTestConfig)); QString l_currentDateTime = QDateTime::currentDateTime().toString("dd-MM-yyyy hh:mm:ss"); l_currentDateTime.append(" TCP Communication Successful "); ui->m_receiverTxtEdit->append(l_currentDateTime); qDebug()<<"TCP Communication Successful"; } catch (Error& e_error) { QString l_currentDateTime = QDateTime::currentDateTime().toString("dd-MM-yyyy hh:mm:ss"); l_currentDateTime.append(" Error during TCP communication creation"); ui->m_receiverTxtEdit->append(l_currentDateTime); qDebug()<<"Error during TCP communication creation"; QMessageBox::critical(this, tr("communication error"), QString::fromStdString(e_error.getMessage())); ***QCoreApplication::exit();*** } catch(...) { QMessageBox::critical(this, tr("unknown error"),tr("MCIS Library communication error ")); }
-
@supratik123 Was the catch (Error& e_error) called? Did you close the QMessageBox::critical dialog? And do you have an event loop running?
-
@supratik123 said in Closing main window from sub windows:
QCoreApplication::exit()
This will quit the eventloop, if none is running, nothing will happen - so does the eventloop run?
Do you have maybe set QApplication::setQuitOnLastWindowClosed(false) somewhere? -
@Christian-Ehrlicher No I haven't set it anywhere
-
@supratik123 then just call exit() (I mean the C lib function).