How to get rid of displaying the same QMessageBox twice in the following c++ code ?
Unsolved
General and Desktop
-
... if (stopTime == 50){ bufferTimer->stop(); configMonitor() ; if (!GetMonitorBrightness(handle,&defaultMinBrightnessLevel, &defaultCurBrightnessLevel, &defaultMaxBrightnessLevel)){ showErrorMessage->setWindowTitle("Error"); // showErrorMessage is a point to QMessageBox showErrorMessage->setIcon(QMessageBox::Critical); showErrorMessage->setStandardButtons(QMessageBox::Ok); showErrorMessage->setText("Failed to get DDC/CI, please check if DDC/CI is Enabled."); showErrorMessage->exec(); this->~EyeCare(); // EyeCare is the QMainWindow } ... void EyeCare::on_closeButton_clicked() { if (bufferTimer->isActive()) stopTime = 50 ; if (!closeButtonClickedForTheFirstTime){ closeButtonClickedForTheFirstTime = true ; if (startcaringButtonClickedForTheFirstTime) changeBrightness(); else{ if (GetMonitorBrightness(handle,&minBrightnessLevel, &curBrightnessLevel,&maxBrightnessLevel)){ showErrorMessage->setWindowTitle("Conform"); showErrorMessage->setIcon(QMessageBox::Question); showErrorMessage->setText("Do you want to set brightness to default or leave it to Eye Care ? "); showErrorMessage->setStandardButtons(QMessageBox::Cancel); showErrorMessage->addButton(tr("Default"),QMessageBox::ActionRole); QPushButton *EyeCare = showErrorMessage->addButton(tr("EyeCare"),QMessageBox::ActionRole); showErrorMessage->setDefaultButton(EyeCare); }else{ showErrorMessage->setWindowTitle("Error"); showErrorMessage->setIcon(QMessageBox::Critical); showErrorMessage->exec(); closeAnimation(); this->close() ; } } ... } ...
I show error message when ' GetMonitorBrightness()' windows api functions fails by returning false.
so I get the same error message twice why ? shouldn't my app close when it encounters this line:
" this->~EyeCare() ; "
is it because they both run as a separate thread ? if yes then how can i terminate the second thread ( on_closeButton_clicked() ) in the first thread so that i can get that error message only once ? -
@Ahti
Please read how C++ manages objects' lifetimes.For the FAQ:
https://isocpp.org/wiki/faq/dtors#dont-call-dtor-on-obj-allocd-via-new