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
Qt 6.11 is out! See what's new in the release blog

QDialog doesn't close

Scheduled Pinned Locked Moved Solved General and Desktop
qdialog
29 Posts 5 Posters 17.0k 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.
  • 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
              • G gabor53

                @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 Offline
                kshegunovK Offline
                kshegunov
                Moderators
                wrote on last edited by
                #21

                @gabor53 said:

                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.

                Which means there's no problem with QMessageBox but with the rest of your code.

                void Additem::close()
                {
                    qDebug() << "Close was called";
                    Additem::reject ();
                }
                

                If close is properly called then you'd see "Close was called" in the debug window. If you don't see that, then close() isn't called. Use the debugger, put a breakpoint at the line where reject() is supposed to be called, if you don't hit the breakpoint, then you have your answer - the code is not executed at all.

                Another thing, Additem::reject(); is a pretty strange way of calling members. Why are you using the fully qualified name to call the method, do you have a reject() override?

                Read and abide by the Qt Code of Conduct

                G 1 Reply Last reply
                0
                • kshegunovK kshegunov

                  @gabor53 said:

                  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.

                  Which means there's no problem with QMessageBox but with the rest of your code.

                  void Additem::close()
                  {
                      qDebug() << "Close was called";
                      Additem::reject ();
                  }
                  

                  If close is properly called then you'd see "Close was called" in the debug window. If you don't see that, then close() isn't called. Use the debugger, put a breakpoint at the line where reject() is supposed to be called, if you don't hit the breakpoint, then you have your answer - the code is not executed at all.

                  Another thing, Additem::reject(); is a pretty strange way of calling members. Why are you using the fully qualified name to call the method, do you have a reject() override?

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

                  @kshegunov
                  I see the "Close was called." message and it goes to reject(). But nothing happens.

                  kshegunovK 1 Reply Last reply
                  0
                  • G gabor53

                    @kshegunov
                    I see the "Close was called." message and it goes to reject(). But nothing happens.

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

                    @gabor53
                    You did not answer my question though.

                    Additem::reject(); is a pretty strange way of calling members. Why are you using the fully qualified name to call the method, do you have a reject() override?

                    Read and abide by the Qt Code of Conduct

                    G 1 Reply Last reply
                    0
                    • kshegunovK kshegunov

                      @gabor53
                      You did not answer my question though.

                      Additem::reject(); is a pretty strange way of calling members. Why are you using the fully qualified name to call the method, do you have a reject() override?

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

                      @kshegunov
                      Sorry. Sorry. I don't have a reject() override. I used the fully qualified name because I tried to use the name different ways just in case one version works. But none of these work:

                      reject()
                      this->reject()
                      Additem::reject()
                      
                      kshegunovK 1 Reply Last reply
                      0
                      • G gabor53

                        @kshegunov
                        Sorry. Sorry. I don't have a reject() override. I used the fully qualified name because I tried to use the name different ways just in case one version works. But none of these work:

                        reject()
                        this->reject()
                        Additem::reject()
                        
                        kshegunovK Offline
                        kshegunovK Offline
                        kshegunov
                        Moderators
                        wrote on last edited by
                        #25

                        @gabor53

                        That's unusual. Please provide the full class declaration of Additem and how you show the dialog.

                        Read and abide by the Qt Code of Conduct

                        G 1 Reply Last reply
                        0
                        • kshegunovK kshegunov

                          @gabor53

                          That's unusual. Please provide the full class declaration of Additem and how you show the dialog.

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

                          @kshegunov
                          Additem declaration (the whole Additem.h):

                          #ifndef ADDITEM_H
                          #define ADDITEM_H
                          
                          #include "review.h"
                          #include "mainwindow.h"
                          #include <QBoxLayout>
                          #include <QDialogButtonBox>
                          #include <QCalendarWidget>
                          #include <QComboBox>
                          #include <QCoreApplication>
                          #include <QDate>
                          #include <QDebug>
                          #include <QDialog>
                          #include <QDialogButtonBox>
                          #include <QDir>
                          #include <QDirModel>
                          #include <QFileSystemModel>
                          #include <QFileDialog>
                          #include <QFlags>
                          #include <QFocusEvent>
                          #include <QFont>
                          #include <QFormLayout>
                          #include <QGridLayout>
                          #include <QIODevice>
                          #include <QLabel>
                          #include <QLineEdit>
                          #include <QListView>
                          #include <QMainWindow>
                          #include <QMessageBox>
                          #include <QPushButton>
                          #include <QScrollArea>
                          #include <QSize>
                          #include <QSizePolicy>
                          #include <QSqlDatabase>
                          #include <QSqlError>
                          #include <QSqlQuery>
                          #include <QStackedLayout>
                          #include <QString>
                          #include <QStringList>
                          #include <QTextEdit>
                          #include <QtCore>
                          #include <QtGlobal>
                          #include <QToolTip>
                          #include <QTreeView>
                          #include <QWidget>
                          #include <QWindow>
                          
                          namespace Ui {
                          class Additem;
                          }
                          
                          
                          
                          class Additem : public QDialog
                          {
                              Q_OBJECT
                          
                          public:
                          
                              //db
                          
                              //Buttons
                              QPushButton *SubmitButton = new QPushButton;
                              QPushButton *Image_Button = new QPushButton("Browse");
                              QPushButton *Reset_Button = new QPushButton;
                          
                              //Functions
                              void 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);
                              void close();
                              void closeAdditem();
                          
                                 QString name;
                          
                              explicit Additem(QWidget *parent = 0);
                              ~Additem();
                          
                          
                          private:
                              Ui::Additem *ui;
                          
                          
                              //Functions
                              void Addcontent();
                              QString getDescription();
                              QString getHistory();
                              void prepAdd();
                              void clear();
                          
                          
                              //QLabel
                              QLabel* title = new QLabel;
                              QLabel *angry_image_Label = new QLabel;
                              QLabel *incorrect_Label = new QLabel;
                              QLabel *spacer1 = new QLabel;
                              QLabel *Label_ID = new QLabel;
                              QLabel *ID_Display = new QLabel;
                              QLabel *Label_Name = new QLabel;
                              QLabel *Label_What = new QLabel; 
                              QLabel *image_Label = new QLabel;
                              QLabel *display_Label = new QLabel;
                              QLabel *Material_Label = new QLabel;
                              QLabel *color_Label = new QLabel;
                              QLabel *descr_Label = new QLabel;
                              QLabel *date_Label = new QLabel;
                              QLabel *month_Label = new QLabel;
                              QLabel *day_Label = new QLabel;
                              QLabel *year_Label = new QLabel;
                              QLabel *spacer2_Label = new QLabel;
                              QLabel *spacer3_label = new QLabel;
                              QLabel *signed_Label = new QLabel;
                              QLabel *history_Label = new QLabel;
                              QLabel *age_Label = new QLabel;
                              QLabel *notes_Label = new QLabel;
                          
                          	//Textedit
                          	QTextEdit * descr_TextEdit = new QTextEdit;
                              QTextEdit *history_TextEdit = new QTextEdit;
                              QTextEdit *notes_TextEdit = new QTextEdit;
                          
                              //Lineedit
                              QLineEdit *age_LineEdit = new QLineEdit;
                          
                              //QCombobox
                              QComboBox *What_Combo = new QComboBox(this);
                              QComboBox *Material_Combo = new QComboBox;
                              QComboBox *color_Combo = new QComboBox;
                              QComboBox *month_Combo = new QComboBox;
                              QComboBox *day_Combo = new QComboBox;
                              QComboBox *year_Combo = new QComboBox;
                              QComboBox *signedby_Combo = new QComboBox;
                          
                              //Layouts
                              QHBoxLayout *name_Layout = new QHBoxLayout;
                              QHBoxLayout *titleLayout = new QHBoxLayout;
                              QHBoxLayout *button_Layout = new QHBoxLayout;
                              QHBoxLayout *dateLayout = new QHBoxLayout;
                          
                              QVBoxLayout *mainLayout = new QVBoxLayout(this);
                          
                              QGridLayout *grid = new QGridLayout;
                          
                              //QString
                              QString fileQstring = "C:/Programming/Projects/FolkFriends/db.db";
                          
                              QSqlDatabase db;
                              QString what;
                              QString newWhat;
                              QString fileName;
                              QString material;
                              QString newMaterial;
                              QString color;
                              QString newColor;
                              QString description;
                              QString si;
                              QString sj;
                              QString sk;
                              QString month;
                              QString day;
                              QString year;
                              QString Signedby;
                              QString newSignedby;
                              QString history;
                              QString age;
                              QString notes;
                              QString submit_warning;
                              QString warning_what;
                              QString submitError;
                              QString sID;
                              QString sIDr;
                          
                              QStringList list;
                          
                              //Int
                              int ItemID = 0;
                              int LastID = 0;
                              int revItemID = 0;
                              int yeark;
                              int r;
                          
                          	//Other
                          
                              QLineEdit *LineEdit_Name = new QLineEdit;
                              QByteArray inByteArray;
                              QByteArray byteArray;
                          
                          private slots:
                              void readAndValidate();
                              void addMonth(int);
                              void resetAll();
                              void submit();
                              void getAge();
                              QString getNotes();
                              void addSignedby(int);
                              void addDay(int);
                              void addYear(int);
                              void getMaterial(int);
                          	void processcombo(int);
                              void addColor(int);
                              QString findimage();
                              void closeAdd();
                          
                          };
                          
                          #endif // ADDITEM_H
                          
                          

                          This is the way I open it from mainwindow.cpp:

                          void MainWindow::on_actionAdd_Item_triggered()
                          {
                              Additem *mAddItem = new Additem;
                              mAddItem->exec ();
                          }
                          
                          kshegunovK jerome_isAviableJ 2 Replies Last reply
                          0
                          • G gabor53

                            @kshegunov
                            Additem declaration (the whole Additem.h):

                            #ifndef ADDITEM_H
                            #define ADDITEM_H
                            
                            #include "review.h"
                            #include "mainwindow.h"
                            #include <QBoxLayout>
                            #include <QDialogButtonBox>
                            #include <QCalendarWidget>
                            #include <QComboBox>
                            #include <QCoreApplication>
                            #include <QDate>
                            #include <QDebug>
                            #include <QDialog>
                            #include <QDialogButtonBox>
                            #include <QDir>
                            #include <QDirModel>
                            #include <QFileSystemModel>
                            #include <QFileDialog>
                            #include <QFlags>
                            #include <QFocusEvent>
                            #include <QFont>
                            #include <QFormLayout>
                            #include <QGridLayout>
                            #include <QIODevice>
                            #include <QLabel>
                            #include <QLineEdit>
                            #include <QListView>
                            #include <QMainWindow>
                            #include <QMessageBox>
                            #include <QPushButton>
                            #include <QScrollArea>
                            #include <QSize>
                            #include <QSizePolicy>
                            #include <QSqlDatabase>
                            #include <QSqlError>
                            #include <QSqlQuery>
                            #include <QStackedLayout>
                            #include <QString>
                            #include <QStringList>
                            #include <QTextEdit>
                            #include <QtCore>
                            #include <QtGlobal>
                            #include <QToolTip>
                            #include <QTreeView>
                            #include <QWidget>
                            #include <QWindow>
                            
                            namespace Ui {
                            class Additem;
                            }
                            
                            
                            
                            class Additem : public QDialog
                            {
                                Q_OBJECT
                            
                            public:
                            
                                //db
                            
                                //Buttons
                                QPushButton *SubmitButton = new QPushButton;
                                QPushButton *Image_Button = new QPushButton("Browse");
                                QPushButton *Reset_Button = new QPushButton;
                            
                                //Functions
                                void 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);
                                void close();
                                void closeAdditem();
                            
                                   QString name;
                            
                                explicit Additem(QWidget *parent = 0);
                                ~Additem();
                            
                            
                            private:
                                Ui::Additem *ui;
                            
                            
                                //Functions
                                void Addcontent();
                                QString getDescription();
                                QString getHistory();
                                void prepAdd();
                                void clear();
                            
                            
                                //QLabel
                                QLabel* title = new QLabel;
                                QLabel *angry_image_Label = new QLabel;
                                QLabel *incorrect_Label = new QLabel;
                                QLabel *spacer1 = new QLabel;
                                QLabel *Label_ID = new QLabel;
                                QLabel *ID_Display = new QLabel;
                                QLabel *Label_Name = new QLabel;
                                QLabel *Label_What = new QLabel; 
                                QLabel *image_Label = new QLabel;
                                QLabel *display_Label = new QLabel;
                                QLabel *Material_Label = new QLabel;
                                QLabel *color_Label = new QLabel;
                                QLabel *descr_Label = new QLabel;
                                QLabel *date_Label = new QLabel;
                                QLabel *month_Label = new QLabel;
                                QLabel *day_Label = new QLabel;
                                QLabel *year_Label = new QLabel;
                                QLabel *spacer2_Label = new QLabel;
                                QLabel *spacer3_label = new QLabel;
                                QLabel *signed_Label = new QLabel;
                                QLabel *history_Label = new QLabel;
                                QLabel *age_Label = new QLabel;
                                QLabel *notes_Label = new QLabel;
                            
                            	//Textedit
                            	QTextEdit * descr_TextEdit = new QTextEdit;
                                QTextEdit *history_TextEdit = new QTextEdit;
                                QTextEdit *notes_TextEdit = new QTextEdit;
                            
                                //Lineedit
                                QLineEdit *age_LineEdit = new QLineEdit;
                            
                                //QCombobox
                                QComboBox *What_Combo = new QComboBox(this);
                                QComboBox *Material_Combo = new QComboBox;
                                QComboBox *color_Combo = new QComboBox;
                                QComboBox *month_Combo = new QComboBox;
                                QComboBox *day_Combo = new QComboBox;
                                QComboBox *year_Combo = new QComboBox;
                                QComboBox *signedby_Combo = new QComboBox;
                            
                                //Layouts
                                QHBoxLayout *name_Layout = new QHBoxLayout;
                                QHBoxLayout *titleLayout = new QHBoxLayout;
                                QHBoxLayout *button_Layout = new QHBoxLayout;
                                QHBoxLayout *dateLayout = new QHBoxLayout;
                            
                                QVBoxLayout *mainLayout = new QVBoxLayout(this);
                            
                                QGridLayout *grid = new QGridLayout;
                            
                                //QString
                                QString fileQstring = "C:/Programming/Projects/FolkFriends/db.db";
                            
                                QSqlDatabase db;
                                QString what;
                                QString newWhat;
                                QString fileName;
                                QString material;
                                QString newMaterial;
                                QString color;
                                QString newColor;
                                QString description;
                                QString si;
                                QString sj;
                                QString sk;
                                QString month;
                                QString day;
                                QString year;
                                QString Signedby;
                                QString newSignedby;
                                QString history;
                                QString age;
                                QString notes;
                                QString submit_warning;
                                QString warning_what;
                                QString submitError;
                                QString sID;
                                QString sIDr;
                            
                                QStringList list;
                            
                                //Int
                                int ItemID = 0;
                                int LastID = 0;
                                int revItemID = 0;
                                int yeark;
                                int r;
                            
                            	//Other
                            
                                QLineEdit *LineEdit_Name = new QLineEdit;
                                QByteArray inByteArray;
                                QByteArray byteArray;
                            
                            private slots:
                                void readAndValidate();
                                void addMonth(int);
                                void resetAll();
                                void submit();
                                void getAge();
                                QString getNotes();
                                void addSignedby(int);
                                void addDay(int);
                                void addYear(int);
                                void getMaterial(int);
                            	void processcombo(int);
                                void addColor(int);
                                QString findimage();
                                void closeAdd();
                            
                            };
                            
                            #endif // ADDITEM_H
                            
                            

                            This is the way I open it from mainwindow.cpp:

                            void MainWindow::on_actionAdd_Item_triggered()
                            {
                                Additem *mAddItem = new Additem;
                                mAddItem->exec ();
                            }
                            
                            kshegunovK Offline
                            kshegunovK Offline
                            kshegunov
                            Moderators
                            wrote on last edited by
                            #27

                            @gabor53

                            I couldn't spot anything that would cause this behavior. My advice is to strip down the code to the bare basics, and then add things in stages to isolate what is causing the problem.

                            Read and abide by the Qt Code of Conduct

                            1 Reply Last reply
                            0
                            • G gabor53

                              @kshegunov
                              Additem declaration (the whole Additem.h):

                              #ifndef ADDITEM_H
                              #define ADDITEM_H
                              
                              #include "review.h"
                              #include "mainwindow.h"
                              #include <QBoxLayout>
                              #include <QDialogButtonBox>
                              #include <QCalendarWidget>
                              #include <QComboBox>
                              #include <QCoreApplication>
                              #include <QDate>
                              #include <QDebug>
                              #include <QDialog>
                              #include <QDialogButtonBox>
                              #include <QDir>
                              #include <QDirModel>
                              #include <QFileSystemModel>
                              #include <QFileDialog>
                              #include <QFlags>
                              #include <QFocusEvent>
                              #include <QFont>
                              #include <QFormLayout>
                              #include <QGridLayout>
                              #include <QIODevice>
                              #include <QLabel>
                              #include <QLineEdit>
                              #include <QListView>
                              #include <QMainWindow>
                              #include <QMessageBox>
                              #include <QPushButton>
                              #include <QScrollArea>
                              #include <QSize>
                              #include <QSizePolicy>
                              #include <QSqlDatabase>
                              #include <QSqlError>
                              #include <QSqlQuery>
                              #include <QStackedLayout>
                              #include <QString>
                              #include <QStringList>
                              #include <QTextEdit>
                              #include <QtCore>
                              #include <QtGlobal>
                              #include <QToolTip>
                              #include <QTreeView>
                              #include <QWidget>
                              #include <QWindow>
                              
                              namespace Ui {
                              class Additem;
                              }
                              
                              
                              
                              class Additem : public QDialog
                              {
                                  Q_OBJECT
                              
                              public:
                              
                                  //db
                              
                                  //Buttons
                                  QPushButton *SubmitButton = new QPushButton;
                                  QPushButton *Image_Button = new QPushButton("Browse");
                                  QPushButton *Reset_Button = new QPushButton;
                              
                                  //Functions
                                  void 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);
                                  void close();
                                  void closeAdditem();
                              
                                     QString name;
                              
                                  explicit Additem(QWidget *parent = 0);
                                  ~Additem();
                              
                              
                              private:
                                  Ui::Additem *ui;
                              
                              
                                  //Functions
                                  void Addcontent();
                                  QString getDescription();
                                  QString getHistory();
                                  void prepAdd();
                                  void clear();
                              
                              
                                  //QLabel
                                  QLabel* title = new QLabel;
                                  QLabel *angry_image_Label = new QLabel;
                                  QLabel *incorrect_Label = new QLabel;
                                  QLabel *spacer1 = new QLabel;
                                  QLabel *Label_ID = new QLabel;
                                  QLabel *ID_Display = new QLabel;
                                  QLabel *Label_Name = new QLabel;
                                  QLabel *Label_What = new QLabel; 
                                  QLabel *image_Label = new QLabel;
                                  QLabel *display_Label = new QLabel;
                                  QLabel *Material_Label = new QLabel;
                                  QLabel *color_Label = new QLabel;
                                  QLabel *descr_Label = new QLabel;
                                  QLabel *date_Label = new QLabel;
                                  QLabel *month_Label = new QLabel;
                                  QLabel *day_Label = new QLabel;
                                  QLabel *year_Label = new QLabel;
                                  QLabel *spacer2_Label = new QLabel;
                                  QLabel *spacer3_label = new QLabel;
                                  QLabel *signed_Label = new QLabel;
                                  QLabel *history_Label = new QLabel;
                                  QLabel *age_Label = new QLabel;
                                  QLabel *notes_Label = new QLabel;
                              
                              	//Textedit
                              	QTextEdit * descr_TextEdit = new QTextEdit;
                                  QTextEdit *history_TextEdit = new QTextEdit;
                                  QTextEdit *notes_TextEdit = new QTextEdit;
                              
                                  //Lineedit
                                  QLineEdit *age_LineEdit = new QLineEdit;
                              
                                  //QCombobox
                                  QComboBox *What_Combo = new QComboBox(this);
                                  QComboBox *Material_Combo = new QComboBox;
                                  QComboBox *color_Combo = new QComboBox;
                                  QComboBox *month_Combo = new QComboBox;
                                  QComboBox *day_Combo = new QComboBox;
                                  QComboBox *year_Combo = new QComboBox;
                                  QComboBox *signedby_Combo = new QComboBox;
                              
                                  //Layouts
                                  QHBoxLayout *name_Layout = new QHBoxLayout;
                                  QHBoxLayout *titleLayout = new QHBoxLayout;
                                  QHBoxLayout *button_Layout = new QHBoxLayout;
                                  QHBoxLayout *dateLayout = new QHBoxLayout;
                              
                                  QVBoxLayout *mainLayout = new QVBoxLayout(this);
                              
                                  QGridLayout *grid = new QGridLayout;
                              
                                  //QString
                                  QString fileQstring = "C:/Programming/Projects/FolkFriends/db.db";
                              
                                  QSqlDatabase db;
                                  QString what;
                                  QString newWhat;
                                  QString fileName;
                                  QString material;
                                  QString newMaterial;
                                  QString color;
                                  QString newColor;
                                  QString description;
                                  QString si;
                                  QString sj;
                                  QString sk;
                                  QString month;
                                  QString day;
                                  QString year;
                                  QString Signedby;
                                  QString newSignedby;
                                  QString history;
                                  QString age;
                                  QString notes;
                                  QString submit_warning;
                                  QString warning_what;
                                  QString submitError;
                                  QString sID;
                                  QString sIDr;
                              
                                  QStringList list;
                              
                                  //Int
                                  int ItemID = 0;
                                  int LastID = 0;
                                  int revItemID = 0;
                                  int yeark;
                                  int r;
                              
                              	//Other
                              
                                  QLineEdit *LineEdit_Name = new QLineEdit;
                                  QByteArray inByteArray;
                                  QByteArray byteArray;
                              
                              private slots:
                                  void readAndValidate();
                                  void addMonth(int);
                                  void resetAll();
                                  void submit();
                                  void getAge();
                                  QString getNotes();
                                  void addSignedby(int);
                                  void addDay(int);
                                  void addYear(int);
                                  void getMaterial(int);
                              	void processcombo(int);
                                  void addColor(int);
                                  QString findimage();
                                  void closeAdd();
                              
                              };
                              
                              #endif // ADDITEM_H
                              
                              

                              This is the way I open it from mainwindow.cpp:

                              void MainWindow::on_actionAdd_Item_triggered()
                              {
                                  Additem *mAddItem = new Additem;
                                  mAddItem->exec ();
                              }
                              
                              jerome_isAviableJ Offline
                              jerome_isAviableJ Offline
                              jerome_isAviable
                              wrote on last edited by jerome_isAviable
                              #28

                              @gabor53
                              please, check that your class is a real QDialog and not a inherited from a QWidget.
                              If it is a QDialog well inherited, and the member function close() is not overrided, then I don't know any reasons for the dialogbox (if it is a real QDialog) not close.

                              eventually, do paste your code: header and source files of this QDialog box who doesn't want to close.
                              (use gist github or ix.io or wich you want for share this code, like that we can look at this closer)

                              1 Reply Last reply
                              0
                              • G Offline
                                G Offline
                                gabor53
                                wrote on last edited by
                                #29

                                Thank you all. I started to rebuild things in hope that solves the problem.

                                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