Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to get rid of displaying the same QMessageBox twice in the following c++ code ?
QtWS25 Last Chance

How to get rid of displaying the same QMessageBox twice in the following c++ code ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qthreadqt 5.7qt creator
2 Posts 2 Posters 1.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Ahti
    wrote on 18 Sept 2016, 13:52 last edited by Ahti
    #1
    ...
    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 ?

    what is a signature ?? Lol

    K 1 Reply Last reply 18 Sept 2016, 19:28
    0
    • A Ahti
      18 Sept 2016, 13:52
      ...
      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 ?

      K Offline
      K Offline
      kshegunov
      Moderators
      wrote on 18 Sept 2016, 19:28 last edited by
      #2

      @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

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      2

      2/2

      18 Sept 2016, 19:28

      • Login

      • Login or register to search.
      2 out of 2
      • First post
        2/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved