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. [SOLVED] - dialog openes several time in MainWindow
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] - dialog openes several time in MainWindow

Scheduled Pinned Locked Moved General and Desktop
11 Posts 4 Posters 2.9k Views 1 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.
  • K Offline
    K Offline
    koahnig
    wrote on last edited by
    #2

    Why does deleteLater not work in your case?
    This happens only when you are pressing "cancel"?

    Vote the answer(s) that helped you to solve your issue(s)

    1 Reply Last reply
    0
    • A Offline
      A Offline
      angelicaP
      wrote on last edited by
      #3

      thanks for your prompt reply.

      1. i'm not sure how to check which is the reason for deleteLater not working. i can confirm has the same symptom as described above.
      2. i haven't try other signal, except cancel. after i press "cancel" and re-open the form, yes, this happens.

      any idea what might be wrong?

      1 Reply Last reply
      0
      • K Offline
        K Offline
        koahnig
        wrote on last edited by
        #4

        The way how you described your problem suggests that it is working correctly with OK button. therefore I was iterating to see, if this is true.
        To give too little information. You need to post more of your code. One needs a crystal ball to give advice.

        You might also want to have a look to the "dialog examples.":http://qt-project.org/doc/qt-5.0/qtwidgets/examples-dialogs.html All those examples should provide you with ideas how to handle a dialog box properly.

        Vote the answer(s) that helped you to solve your issue(s)

        1 Reply Last reply
        0
        • R Offline
          R Offline
          raf924
          wrote on last edited by
          #5

          [quote author="angelicaP" date="1372006390"]

          i Cancel the form with:

          @void newA::on_pushButton_clicked()
          {
          newA::close();
          }@

          [/quote]

          But why not using close() directly?

          1 Reply Last reply
          0
          • A Offline
            A Offline
            angelicaP
            wrote on last edited by
            #6

            i’m back with some code. Still have the same issue:

            @mainwindow.h
            #ifndef MAINWINDOW_H
            #define MAINWINDOW_H

            #include <QMainWindow>

            namespace Ui {
            class MainWindow;
            }

            class MainWindow : public QMainWindow
            {
            Q_OBJECT

            public:
            explicit MainWindow(QWidget *parent = 0);
            ~MainWindow();

            private slots:
            void on_actionA_2_triggered();

            private:
            Ui::MainWindow *ui;
            };

            #endif // MAINWINDOW_H

            Newa.h
            #ifndef NEWA_H
            #define NEWA_H

            #include <QDialog>

            namespace Ui {
            class newA;
            }

            class newA : public QDialog
            {
            Q_OBJECT

            public:
            explicit newA(QWidget *parent = 0);
            ~newA();

            private slots:
            void on_addE1Info_clicked();

            void on_pushButton_2_clicked();
            

            private:
            Ui::newA *ui;
            };

            #endif // NEWA_H

            Newe.h

            #ifndef NEWE_H
            #define NEWE_H

            #include <QDialog>

            namespace Ui {
            class newe;
            }

            class newe : public QDialog
            {
            Q_OBJECT

            public:
            explicit newe(QWidget *parent = 0);
            ~newe();

            private slots:

            void on_pushButton_clicked();
            

            private:
            Ui::newe *ui;
            };

            #endif // NEWE_H

            Main.cpp
            #include "mainwindow.h"
            #include <QApplication>
            #include <QDialog>

            int main(int argc, char *argv[])
            {
            QApplication a(argc, argv);
            MainWindow w;
            w.show();

            return a.exec&#40;&#41;;
            

            }

            Mainwindow.cpp
            #include "mainwindow.h"
            #include "ui_mainwindow.h"
            #include "newa.h"
            #include "newe.h"
            #include <QToolButton>
            #include <QtCore>
            #include <QTabWidget>
            #include <QLabel>
            #include <QScrollArea>
            #include <QDebug>

            MainWindow::MainWindow(QWidget *parent) :
            QMainWindow(parent),
            ui(new Ui::MainWindow)
            {
            ui->setupUi(this);
            QMainWindow::showMaximized();
            QScrollArea * scrollArea = new QScrollArea();
            setCentralWidget(scrollArea);
            scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
            scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);

            }
            MainWindow::~MainWindow()
            {
            delete ui;
            }

            void MainWindow::on_actionA_2_triggered()
            {
            connect(ui->actionA_2, SIGNAL(triggered()), this , SLOT(on_actionA_2_triggered()));
            newA *nA = new newA;
            nA->show();

            Newa.cpp
            #include "mainwindow.h"
            #include "newa.h"
            #include "ui_newa.h"
            #include "newe.h"
            #include <QScrollArea>
            #include <QtCore>
            #include <QMainWindow>
            #include <QTabWidget>
            #include <QLabel>

            newA::newA(QWidget *parent) :
            QDialog(parent),
            ui(new Ui::newA)
            {
            ui->setupUi(this);

            }

            newA::~newA()
            {
            delete ui;
            }

            void newA::on_addE1Info_clicked()
            { connect(ui->addE1Info, SIGNAL(clicked()), this, SLOT(on_addE1Info_clicked()));
            newe * aE = new newe();
            aE->show();

            }

            void newA::on_pushButton_2_clicked()
            {
            close();
            }

            newe.cpp
            #include "newe.h"
            #include "ui_newe.h"
            #include "newa.h"
            #include <QString>

            newe::newe(QWidget *parent):
            QDialog(parent),
            ui(new Ui::newe)
            {
            ui->setupUi(this);
            }

            newe::~newe()
            {
            delete ui;
            }

            void newe::on_pushButton_clicked()
            {
            close();
            deleteLater();
            }@

            What i’m trying to say is the following: after i compile and run the project and I press one time the buttons, they work fine. If i close the form newe.ui and reopen it (void newA::on_addE1Info_clicked()
            ), this form will reopen twice. If i close both of them and reopen it, this form will open x 4, and so on; every time the number of same form opened windows are = the number of the “sesions” opened after the compile/build x 2 (times 2).

            Why is happening this?

            Ps: probably you will notice a lot of issues with my code, don’t consider them please, this is a draft.

            Thanks for your input.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #7

              Hi,

              Please enclose your code with coding tags, it will make it more readable. One thing that is problematic is that each time you call on_actionA_2_triggered or on_addE1Info_clicked you are adding the same connection again which means these slots will be called twice as much each time

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • A Offline
                A Offline
                angelicaP
                wrote on last edited by
                #8

                SGaist you are right, next time I will use the codding tags. I corrected this issue very easy, taking out the second slot call. Thank you for your comment. This thread is SOLVED.

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #9

                  You're welcome !

                  You can always edit your post and add the tags :)

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    angelicaP
                    wrote on last edited by
                    #10

                    like this? :)

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #11

                      Exactly :)

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      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