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. QDialog doesn't close

QDialog doesn't close

Scheduled Pinned Locked Moved Solved General and Desktop
qdialog
29 Posts 5 Posters 16.6k Views 4 Watching
  • 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.
  • G Offline
    G Offline
    gabor53
    wrote on last edited by
    #1

    Hi,
    I'm trying to close a QDialog from a QMessageBox using the following code:

                              QMessageBox msgBox;
                              QPushButton *OKButton = msgBox.addButton (tr("OK"),QMessageBox::RejectRole);
                              msgBox.setText ("<b><font size = '16' color = 'green'>The Friend was added to the database. To add more press CTRL A.");
                              msgBox.exec ();
    
                              if(msgBox.clickedButton () == OKButton)
                              {
                                 qDebug() << "OK was clicked.";
    
                                  this->reject ();
    

    There is no error message, but t doesn't close or do anything. The messagebox is generated by the same QDialog I'm trying to close and it was opened usint Additem.exe(). What am I doing incorrectly?
    Thank you for your help.

    kshegunovK jerome_isAviableJ 2 Replies Last reply
    0
    • miclandM Offline
      miclandM Offline
      micland
      wrote on last edited by micland
      #2

      Do you see the debug message? Will say, is your code not entering the if clause or is just the reject() call ignored?

      G 1 Reply Last reply
      0
      • miclandM micland

        Do you see the debug message? Will say, is your code not entering the if clause or is just the reject() call ignored?

        G Offline
        G Offline
        gabor53
        wrote on last edited by
        #3

        @micland
        It is entering the if clause but ignores the reject(). It also ignores close(), finished(), accept(). No error message just does nothing.

        miclandM 1 Reply Last reply
        0
        • G gabor53

          @micland
          It is entering the if clause but ignores the reject(). It also ignores close(), finished(), accept(). No error message just does nothing.

          miclandM Offline
          miclandM Offline
          micland
          wrote on last edited by
          #4

          @gabor53 said:

          It is entering the if clause but ignores the reject(). It also ignores close(), finished(), accept(). No error message just does nothing.

          Ok so the button is correctly evaluated. Did you eventually override QDialog::closeEvent(...)?

          G 1 Reply Last reply
          0
          • miclandM micland

            @gabor53 said:

            It is entering the if clause but ignores the reject(). It also ignores close(), finished(), accept(). No error message just does nothing.

            Ok so the button is correctly evaluated. Did you eventually override QDialog::closeEvent(...)?

            G Offline
            G Offline
            gabor53
            wrote on last edited by
            #5

            @micland
            No. If I have to do it, can you please show me how?

            miclandM 1 Reply Last reply
            0
            • G gabor53

              @micland
              No. If I have to do it, can you please show me how?

              miclandM Offline
              miclandM Offline
              micland
              wrote on last edited by
              #6

              @gabor53
              No you don't have to - but if you do you can prevent that the dialog gets closed by rejecting the event. That was my question if you did this accidentaly. So I have no idea what your problem could be... :-/

              1 Reply Last reply
              1
              • mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #7

                hi
                is the messagbox code inside the QDialog ?
                there is no way it can ignore this->close(); ???
                unless u override
                void QDialog::closeEvent(QCloseEvent * e)
                and ignore it.

                1 Reply Last reply
                0
                • G gabor53

                  Hi,
                  I'm trying to close a QDialog from a QMessageBox using the following code:

                                            QMessageBox msgBox;
                                            QPushButton *OKButton = msgBox.addButton (tr("OK"),QMessageBox::RejectRole);
                                            msgBox.setText ("<b><font size = '16' color = 'green'>The Friend was added to the database. To add more press CTRL A.");
                                            msgBox.exec ();
                  
                                            if(msgBox.clickedButton () == OKButton)
                                            {
                                               qDebug() << "OK was clicked.";
                  
                                                this->reject ();
                  

                  There is no error message, but t doesn't close or do anything. The messagebox is generated by the same QDialog I'm trying to close and it was opened usint Additem.exe(). What am I doing incorrectly?
                  Thank you for your help.

                  kshegunovK Offline
                  kshegunovK Offline
                  kshegunov
                  Moderators
                  wrote on last edited by
                  #8

                  @gabor53

                  Hi,
                  Do you mind providing the whole function? Is it a slot? How is it called/connected?
                  As a side question, why don't you use the standard buttons?

                  Kind regards.

                  Read and abide by the Qt Code of Conduct

                  G 1 Reply Last reply
                  0
                  • kshegunovK kshegunov

                    @gabor53

                    Hi,
                    Do you mind providing the whole function? Is it a slot? How is it called/connected?
                    As a side question, why don't you use the standard buttons?

                    Kind regards.

                    G Offline
                    G Offline
                    gabor53
                    wrote on last edited by
                    #9

                    @kshegunov
                    Hi,
                    I tried the standard buttons but they didn't work either. Here is the whole function:

                    void Additem::FunctAddtoDb(QString sIDr, QString namer, QString newWhatr, QString newMaterialr, QString newColorr, QString descriptionr, QString monthr, QString dayr, QString yearr, QString newSignedbyr, QString historyr, QString ager, QString notesr, QByteArray byteArrayr)
                    {
                        {
                                QSqlDatabase db = QSqlDatabase::addDatabase ("QSQLITE","add");
                            db.setDatabaseName ("C:/Programming/Projects/FolkFriends/db.db");
                            bool OKadd = db.open ();
                            QSqlQuery querys(db);
                    
                        //    if(!db.open ())
                            if(OKadd == false)
                            {
                                qDebug() << "The database is not open (submit)!";
                            }
                            else
                            {
                                qDebug() << "The database is open (submit)!";
                            }
                    
                    
                    
                    //                       qDebug() << "Original data " <<byteArray.size() << "bytes.";
                    
                    //                       qDebug() <<"Byte size: " << byteArray.size();
                    
                    //                       qDebug() << "sID (from FunctAdd): " << sIDr;
                    //                       qDebug() << "name (from FunctAdd): " << namer;
                    
                    
                    
                                           querys.prepare("INSERT INTO Items (ID, Name, Pic, Description, Month, Day, Year, History, Age, Notes, Color, Material, Signed, What) VALUES(:ID, :Name, :Pic, :Description, :Month, :Day, :Year, :History, :Age, :Notes, :Color, :Material, :Signed, :What)" );
                                              querys.bindValue (":ID",sIDr);
                                              querys.bindValue (":Name",namer);
                                              querys.bindValue (":Pic",byteArrayr);
                                              querys.bindValue (":Description",descriptionr);
                                              querys.bindValue (":Month",monthr);
                                              querys.bindValue (":Day",dayr);
                                              querys.bindValue (":Year",yearr);
                                              querys.bindValue (":History",historyr);
                                              querys.bindValue (":Age",ager);
                                              querys.bindValue (":Notes",notesr);
                                              querys.bindValue (":Color",newColorr);
                                              querys.bindValue (":Material",newMaterialr);
                                              querys.bindValue (":Signed",newSignedbyr);
                                              querys.bindValue (":What",newWhatr);
                    
                                          bool result = querys.exec ();
                    
                                          if(!result)
                                          {
                                              qDebug() <<"Error inserting into the main db!" << querys.lastError ();
                    
                                              QMessageBox::warning (this,"Add to Database Warning","<b><font size='16' color='red'>Error 1002: The Friend was not added to the database.");
                                          }
                                          else
                                          {
                    
                                              qDebug() << "Entered FunctAdd OK loop.";
                    
                                              QMessageBox msgBox;
                                              QPushButton *OKButton = msgBox.addButton (tr("OK"),QMessageBox::RejectRole);
                                              msgBox.setText ("<b><font size = '16' color = 'green'>The Friend was added to the database. To add more press CTRL A.");
                                              msgBox.exec ();
                                              if(msgBox.clickedButton () == OKButton)
                                              {
                                                 qDebug() << "OK was clicked.";
                                                  this->reject ();
                                              }
                                          }
                    
                                         db.close ();
                    
                        }
                    
                        QSqlDatabase::removeDatabase ("add");
                    }
                    
                    void Additem::close()
                    {
                        qDebug() << "Close was called";
                        Additem::reject ();
                    }
                    

                    Thank you.

                    1 Reply Last reply
                    0
                    • G gabor53

                      Hi,
                      I'm trying to close a QDialog from a QMessageBox using the following code:

                                                QMessageBox msgBox;
                                                QPushButton *OKButton = msgBox.addButton (tr("OK"),QMessageBox::RejectRole);
                                                msgBox.setText ("<b><font size = '16' color = 'green'>The Friend was added to the database. To add more press CTRL A.");
                                                msgBox.exec ();
                      
                                                if(msgBox.clickedButton () == OKButton)
                                                {
                                                   qDebug() << "OK was clicked.";
                      
                                                    this->reject ();
                      

                      There is no error message, but t doesn't close or do anything. The messagebox is generated by the same QDialog I'm trying to close and it was opened usint Additem.exe(). What am I doing incorrectly?
                      Thank you for your help.

                      jerome_isAviableJ Offline
                      jerome_isAviableJ Offline
                      jerome_isAviable
                      wrote on last edited by jerome_isAviable
                      #10

                      @gabor53 you no need to do that for use QMessageBox.
                      The easy could be (for me) to call messageBox from conditionnal error test, and use the buttons allready provided (if need to use/add button, it steal easy to):

                      bool error(true);
                      QString my_datas("test");
                      if(error)
                        QMessageBox::warning(this, tr("my title window"), tr("my error message: %1").arg(my_datas));
                      

                      also, QMessageBox (like all Dialog box by default) will send back a int answer type object. So "switch()" C++ function should catch answer back after close.
                      And also, you can give name of your buttons directly from warning member function, et the end...). Look at API for QMessageBox, there is some examples.
                      Also, if your code is outside of messageBox (that seems to be the fact in your code), first, your condition will be read after the messagebox closed... if you want to read things before, so you have to put the code inside (so inherit QMessageBox for that). or use "QObject::connect" method for pass signal from QMEssageBox to a slot who will do what you want other.
                      But if it is just for close QMEssageBox, you absolutly not need all of this you try to do, but only call QMessageBox as i show you, it will have OK button allready inside, and it will work directly out of the "QMessageBox"... if not, there is a problem.

                      Also... if you want to cath QMessageBox buttons events, you have to first declare a pointer on QMessageBox for use it from a QObject::connect (and your class has to have QOBJECT macro inside declaration somewhere for ba able to use connections).
                      example:

                      QMessageBox *mgx;
                      mgx = new QMessageBox(this);
                      mgx.warning(this, tr("my title window"), tr("my text"));
                      mgx.setStyleSheet("QLabel{color: green; font-size: 16;} QWidget{background-color: white;}"); // all the CSS style you want to give to your content... should go there in CSS style code with some features like wich object should have wich CSS "paint"
                      connect(mgx, SIGNAL(buttonClicked(QAbstractButton), this, SLOT(on_OK_mgx_clicked(QAbstractButton));
                      mgx->open();
                      

                      also, you have to create the function member declared as private (or public) slot, and then define it in cpp file (void on_OK_mgx_clicked(QAbstractButton button); in header file, then define it in source file linked.
                      that way you will catch button clicked returned by QAbstractButton object from clecked event in QMessageBox. But i think it is not what you are searching for... this is more complictae than use default mechanism for print a message with a close button.

                      If you want more features, try first like that, play around after read the API on that, and ask more precisely what you try to do with QMessageBox (what is the finality).
                      http://doc.qt.io/qt-4.8/qmessagebox.html#buttonClicked
                      Hope that help.

                      G 1 Reply Last reply
                      0
                      • jerome_isAviableJ jerome_isAviable

                        @gabor53 you no need to do that for use QMessageBox.
                        The easy could be (for me) to call messageBox from conditionnal error test, and use the buttons allready provided (if need to use/add button, it steal easy to):

                        bool error(true);
                        QString my_datas("test");
                        if(error)
                          QMessageBox::warning(this, tr("my title window"), tr("my error message: %1").arg(my_datas));
                        

                        also, QMessageBox (like all Dialog box by default) will send back a int answer type object. So "switch()" C++ function should catch answer back after close.
                        And also, you can give name of your buttons directly from warning member function, et the end...). Look at API for QMessageBox, there is some examples.
                        Also, if your code is outside of messageBox (that seems to be the fact in your code), first, your condition will be read after the messagebox closed... if you want to read things before, so you have to put the code inside (so inherit QMessageBox for that). or use "QObject::connect" method for pass signal from QMEssageBox to a slot who will do what you want other.
                        But if it is just for close QMEssageBox, you absolutly not need all of this you try to do, but only call QMessageBox as i show you, it will have OK button allready inside, and it will work directly out of the "QMessageBox"... if not, there is a problem.

                        Also... if you want to cath QMessageBox buttons events, you have to first declare a pointer on QMessageBox for use it from a QObject::connect (and your class has to have QOBJECT macro inside declaration somewhere for ba able to use connections).
                        example:

                        QMessageBox *mgx;
                        mgx = new QMessageBox(this);
                        mgx.warning(this, tr("my title window"), tr("my text"));
                        mgx.setStyleSheet("QLabel{color: green; font-size: 16;} QWidget{background-color: white;}"); // all the CSS style you want to give to your content... should go there in CSS style code with some features like wich object should have wich CSS "paint"
                        connect(mgx, SIGNAL(buttonClicked(QAbstractButton), this, SLOT(on_OK_mgx_clicked(QAbstractButton));
                        mgx->open();
                        

                        also, you have to create the function member declared as private (or public) slot, and then define it in cpp file (void on_OK_mgx_clicked(QAbstractButton button); in header file, then define it in source file linked.
                        that way you will catch button clicked returned by QAbstractButton object from clecked event in QMessageBox. But i think it is not what you are searching for... this is more complictae than use default mechanism for print a message with a close button.

                        If you want more features, try first like that, play around after read the API on that, and ask more precisely what you try to do with QMessageBox (what is the finality).
                        http://doc.qt.io/qt-4.8/qmessagebox.html#buttonClicked
                        Hope that help.

                        G Offline
                        G Offline
                        gabor53
                        wrote on last edited by
                        #11

                        @jerome_isAviable
                        Thanks. The thing is I want to close the dialog called Additem that called QMessageBox.
                        QMessageBox closes wonderfully but any attempt to close Additem is disregarded.

                        kshegunovK jerome_isAviableJ 2 Replies Last reply
                        0
                        • G gabor53

                          @jerome_isAviable
                          Thanks. The thing is I want to close the dialog called Additem that called QMessageBox.
                          QMessageBox closes wonderfully but any attempt to close Additem is disregarded.

                          kshegunovK Offline
                          kshegunovK Offline
                          kshegunov
                          Moderators
                          wrote on last edited by
                          #12

                          @gabor53

                          Are you sure msgBox.clickedButton() isn't NULL? This might happen if the message box was dismissed with a key.

                          Read and abide by the Qt Code of Conduct

                          G 1 Reply Last reply
                          0
                          • kshegunovK kshegunov

                            @gabor53

                            Are you sure msgBox.clickedButton() isn't NULL? This might happen if the message box was dismissed with a key.

                            G Offline
                            G Offline
                            gabor53
                            wrote on last edited by
                            #13

                            @kshegunov
                            How can I check?

                            kshegunovK 1 Reply Last reply
                            0
                            • G gabor53

                              @kshegunov
                              How can I check?

                              kshegunovK Offline
                              kshegunovK Offline
                              kshegunov
                              Moderators
                              wrote on last edited by
                              #14

                              @gabor53
                              As you'd check any other pointer:

                              QAbstractButton * clickedButton = msgBox.clickedButton();
                              if (!clickedButton)  {
                                  qDebug() << "Well, we are out of luck. "
                                      << "The message box was dismissed with a key so this check: "
                                      << "msgBox.clickedButton () == OKButton is meaningless" << endl;
                              }
                              

                              Read and abide by the Qt Code of Conduct

                              G 1 Reply Last reply
                              0
                              • kshegunovK kshegunov

                                @gabor53
                                As you'd check any other pointer:

                                QAbstractButton * clickedButton = msgBox.clickedButton();
                                if (!clickedButton)  {
                                    qDebug() << "Well, we are out of luck. "
                                        << "The message box was dismissed with a key so this check: "
                                        << "msgBox.clickedButton () == OKButton is meaningless" << endl;
                                }
                                
                                G Offline
                                G Offline
                                gabor53
                                wrote on last edited by
                                #15

                                @kshegunov
                                I did the following (before you posted your last message):

                                 if(msgBox.clickedButton () == NULL)
                                                          {
                                                              qDebug() << "ClickButton is null";
                                                          }
                                                          else
                                                          {
                                                              qDebug() << "ClickButton is NOT null.";
                                                          }
                                                          
                                

                                According to this code the clickedButton() is not NULL.

                                kshegunovK 1 Reply Last reply
                                0
                                • G gabor53

                                  @kshegunov
                                  I did the following (before you posted your last message):

                                   if(msgBox.clickedButton () == NULL)
                                                            {
                                                                qDebug() << "ClickButton is null";
                                                            }
                                                            else
                                                            {
                                                                qDebug() << "ClickButton is NOT null.";
                                                            }
                                                            
                                  

                                  According to this code the clickedButton() is not NULL.

                                  kshegunovK Offline
                                  kshegunovK Offline
                                  kshegunov
                                  Moderators
                                  wrote on last edited by
                                  #16

                                  @gabor53
                                  Okay then, going to the basics. Can you confirm that the this->reject() is called? That is, do you get the debug message "OK was clicked.".
                                  Another thing I just noticed:
                                  Why do you have an overload for reject()? This is usually not necessary, can you show that function and its declaration?

                                  Kind regards.

                                  Read and abide by the Qt Code of Conduct

                                  1 Reply Last reply
                                  0
                                  • G gabor53

                                    @jerome_isAviable
                                    Thanks. The thing is I want to close the dialog called Additem that called QMessageBox.
                                    QMessageBox closes wonderfully but any attempt to close Additem is disregarded.

                                    jerome_isAviableJ Offline
                                    jerome_isAviableJ Offline
                                    jerome_isAviable
                                    wrote on last edited by jerome_isAviable
                                    #17

                                    @gabor53 ok, well i understand better.
                                    so you need to use it like that:

                                    QMessageBox mgx;
                                    int answer = mgx.warning(this, "my fix title", "my fix text");
                                    if(answer == Qt::accept())
                                        this->close();
                                    

                                    that's all.

                                    or with a question to validate:

                                    int answer = QMessageBox::question( this,
                                                           tr("Question tag..."),
                                                           tr("read the error:/n%1 ").arg(error_string),
                                                           tr("Close"), tr("Not close"));
                                    if(answer == 1)
                                        this->close();
                                    

                                    and... don't forget to tell us (for share for other who will have same problem) finally what solution you choosed and worked for you and make the subject as "resolved" (said thank you for helpers time is also a nice option i like sometimes to read or write...).
                                    thank you.

                                    G 1 Reply Last reply
                                    0
                                    • jerome_isAviableJ jerome_isAviable

                                      @gabor53 ok, well i understand better.
                                      so you need to use it like that:

                                      QMessageBox mgx;
                                      int answer = mgx.warning(this, "my fix title", "my fix text");
                                      if(answer == Qt::accept())
                                          this->close();
                                      

                                      that's all.

                                      or with a question to validate:

                                      int answer = QMessageBox::question( this,
                                                             tr("Question tag..."),
                                                             tr("read the error:/n%1 ").arg(error_string),
                                                             tr("Close"), tr("Not close"));
                                      if(answer == 1)
                                          this->close();
                                      

                                      and... don't forget to tell us (for share for other who will have same problem) finally what solution you choosed and worked for you and make the subject as "resolved" (said thank you for helpers time is also a nice option i like sometimes to read or write...).
                                      thank you.

                                      G Offline
                                      G Offline
                                      gabor53
                                      wrote on last edited by
                                      #18

                                      @jerome_isAviable
                                      I implemented this:

                                                            {
                                                                qDebug() <<"Error inserting into the main db!" << querys.lastError ();
                                      
                                                                QMessageBox::warning (this,"Add to Database Warning","<b><font size='16' color='red'>Error 1002: The Friend was not added to the database.");
                                                            }
                                                            else
                                                            {
                                      
                                                                qDebug() << "Entered FunctAdd OK loop.";
                                      
                                                                QMessageBox msgBox;
                                      
                                      			int answer = msgBox.information (this,
                                                                                   tr("Confirmation"),
                                                                                   tr("<b><font size = '16' color = 'green'>The Friend was added to the database. To add more press CTRL A."),
                                                                                   QMessageBox::Close);
                                      
                                      				if(answer == QMessageBox::Close)
                                                      {
                                                         this->close();
                                                      }
                                      
                                                            }
                                      
                                                           db.close ();
                                      }
                                          }
                                      

                                      There are no error messages, and it enters the right loop
                                      (displays " qDebug() << "Entered FunctAdd OK loop.";)
                                      but the Additem dialog is still not closed. I have no idea why.

                                      jerome_isAviableJ 1 Reply Last reply
                                      0
                                      • G gabor53

                                        @jerome_isAviable
                                        I implemented this:

                                                              {
                                                                  qDebug() <<"Error inserting into the main db!" << querys.lastError ();
                                        
                                                                  QMessageBox::warning (this,"Add to Database Warning","<b><font size='16' color='red'>Error 1002: The Friend was not added to the database.");
                                                              }
                                                              else
                                                              {
                                        
                                                                  qDebug() << "Entered FunctAdd OK loop.";
                                        
                                                                  QMessageBox msgBox;
                                        
                                        			int answer = msgBox.information (this,
                                                                                     tr("Confirmation"),
                                                                                     tr("<b><font size = '16' color = 'green'>The Friend was added to the database. To add more press CTRL A."),
                                                                                     QMessageBox::Close);
                                        
                                        				if(answer == QMessageBox::Close)
                                                        {
                                                           this->close();
                                                        }
                                        
                                                              }
                                        
                                                             db.close ();
                                        }
                                            }
                                        

                                        There are no error messages, and it enters the right loop
                                        (displays " qDebug() << "Entered FunctAdd OK loop.";)
                                        but the Additem dialog is still not closed. I have no idea why.

                                        jerome_isAviableJ Offline
                                        jerome_isAviableJ Offline
                                        jerome_isAviable
                                        wrote on last edited by
                                        #19

                                        @gabor53 try to use default message box button (not add QMessageBox::Close in information)
                                        and use condition if(answer == 0) instead.
                                        But... the principe is that, if your messagebox is modal, then the message box is waiting for you push button "OK" before the code ga ahead... right ?
                                        so finally, condition serve nothing (there is only one button... condition serve for what ?).
                                        finaly, just don't use condition but this->close() after QMessageBox::information.
                                        Also, no need to declare QMessageBox mgx in this situation, directly call QMessageBox::information(....);
                                        declare a variable for contain an object (QMessageBox or other) serve for add stuff/options and use it in other situation you not need here.

                                        so the code you need should also be:

                                        QMessageBox::information (this, tr("Confirmation"), tr("<b><font size = '16' color = 'green'>The Friend was added to the database. To add more press CTRL A."));
                                        this->close();
                                        

                                        as soon as possible: do it simple, do it easy.

                                        on my codes (if i well understand what you are doing), i use a QMessageBox::question for ask if the user want to create an other one new object, if he want i clear entries or not for that or if it is finish. Then from there, i catch the answer (who is the number of button pushed) for call action like close or not, and function for delete entries of this dialog box or not. So when i'm waiting for know what the user want to do next, i ask him what him want. (i not said it is a good idea... there is many... but... it is an idea).
                                        Did you try the code i share with you with QMessageBox::question ? this one works sure.
                                        also, for see what int answer give you, you could try to add a "qDebug() << answer;" The retrurn depend of the function you call and the button you push. This would help you to see what to catch in condition for do what you want (i do like that when i'm not sure or when something not works like i would like...).

                                        G 1 Reply Last reply
                                        0
                                        • jerome_isAviableJ jerome_isAviable

                                          @gabor53 try to use default message box button (not add QMessageBox::Close in information)
                                          and use condition if(answer == 0) instead.
                                          But... the principe is that, if your messagebox is modal, then the message box is waiting for you push button "OK" before the code ga ahead... right ?
                                          so finally, condition serve nothing (there is only one button... condition serve for what ?).
                                          finaly, just don't use condition but this->close() after QMessageBox::information.
                                          Also, no need to declare QMessageBox mgx in this situation, directly call QMessageBox::information(....);
                                          declare a variable for contain an object (QMessageBox or other) serve for add stuff/options and use it in other situation you not need here.

                                          so the code you need should also be:

                                          QMessageBox::information (this, tr("Confirmation"), tr("<b><font size = '16' color = 'green'>The Friend was added to the database. To add more press CTRL A."));
                                          this->close();
                                          

                                          as soon as possible: do it simple, do it easy.

                                          on my codes (if i well understand what you are doing), i use a QMessageBox::question for ask if the user want to create an other one new object, if he want i clear entries or not for that or if it is finish. Then from there, i catch the answer (who is the number of button pushed) for call action like close or not, and function for delete entries of this dialog box or not. So when i'm waiting for know what the user want to do next, i ask him what him want. (i not said it is a good idea... there is many... but... it is an idea).
                                          Did you try the code i share with you with QMessageBox::question ? this one works sure.
                                          also, for see what int answer give you, you could try to add a "qDebug() << answer;" The retrurn depend of the function you call and the button you push. This would help you to see what to catch in condition for do what you want (i do like that when i'm not sure or when something not works like i would like...).

                                          G Offline
                                          G Offline
                                          gabor53
                                          wrote on last edited by
                                          #20

                                          @jerome_isAviable
                                          Thank you. I really understand how this work. I guess the problem is that

                                          this->close()
                                          

                                          doesn't work no matter how I write QMessageBox. It doesn't even work, when there is no QMessageBox.

                                          kshegunovK 1 Reply Last reply
                                          0

                                          • Login

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