Solved QDialog doesn't close
-
@jerome_isAviable
Thank you. I really understand how this work. I guess the problem is thatthis->close()
doesn't work no matter how I write QMessageBox. It doesn't even work, when there is no QMessageBox.
-
@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 wherereject()
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 areject()
override? -
@kshegunov
I see the "Close was called." message and it goes to reject(). But nothing happens. -
@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?
-
@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()
-
That's unusual. Please provide the full class declaration of
Additem
and how you show the dialog. -
@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 (); }
-
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.
-
@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) -
Thank you all. I started to rebuild things in hope that solves the problem.