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. Classes communication / signal slot generates duplicate connection error
Forum Update on Monday, May 27th 2025

Classes communication / signal slot generates duplicate connection error

Scheduled Pinned Locked Moved General and Desktop
29 Posts 4 Posters 6.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #20

    You can't pass parameters in connect statements (please take some time to read the "Signals And Slots" chapter in Qt's documentation.

    What's the use of Dialog2 ? Get a string from the user ? Then call exec on the dialog. Check it's return value. If it's okay then call directly addNewTab retrieving the string from Dialog2 through a getter.

    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
      #21

      hi,
      when I simplified my test example I missed a detail. sorry for this, a lot of effort has already been put in this thread: in mainWindow I have an action when triggered, opens dialog1. In dialog1 is the pushButton that should open dialog2. maybe this makes sense. how is this scenario changes the output.

      bq. You can’t pass parameters in connect statements (please take some time to read the “Signals And Slots” chapter in Qt’s documentation.

      understood from Signals and Slots.

      below my code from mainWindow.h and .cpp. the rest remains as in my previous post - entire code.

      @//mainwindow.h
      #ifndef MAINWINDOW_H
      #define MAINWINDOW_H

      #include <QMainWindow>
      #include <QTabWidget>
      #include "dialog1.h"
      #include "dialog2.h"
      #include <QMessageBox>
      #include <QString>
      #include <QWidget>

      namespace Ui {
      class MainWindow;
      }

      class MainWindow : public QMainWindow
      {
      Q_OBJECT

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

      private:
      Ui::MainWindow *ui;

      private slots:
      void addNewTab(QWidget * page, QString & title)
      {
      QTabWidget *newTab = new QTabWidget;

          setCentralWidget(newTab); // only for testing, otherwise generates one single tab always. previous post
          newTab->addTab(page, title);
          newTab->setTabsClosable(true);
      }
      void on_actionDialog1_triggered();
      

      };

      #endif // MAINWINDOW_H

      //mainwindow.cpp
      #include "mainwindow.h"
      #include "ui_mainwindow.h"
      #include "dialog1.h"
      #include "dialog2.h"
      #include <QTabWidget>

      MainWindow::MainWindow(QWidget *parent) :
      QMainWindow(parent),
      ui(new Ui::MainWindow)
      {
      ui->setupUi(this);
      Dialog1 *d1 = new Dialog1;
      Dialog2 *d2 = new Dialog2;

      //here should come the connect function that connects dialog1 to open a dialog2 in mainwindow tabWidget. this is generating my problem.

      }

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

      void MainWindow::on_actionDialog1_triggered()
      {
      QString titled1 = "title d1";
      Dialog1 *d1 = new Dialog1;
      addNewTab(d1, titled1);
      }@

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

        If Dialog2 is open within Dialog1, what does it do in MainWindow ?

        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
          #23

          dialog2 should be open by dialog1 within the tabWidget in MainWindow.

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

            What does Dialog1 contain ? How should it be shown ?

            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
              #25

              thank you for your feedback,

              @//dialog1.cpp
              #include "dialog1.h"
              #include "ui_dialog1.h"
              #include "mainwindow.h"

              Dialog1::Dialog1(QWidget *parent) :
              QDialog(parent),
              ui(new Ui::Dialog1)
              {
              ui->setupUi(this);
              Dialog2 *d2 = new Dialog2;
              QString titled2 = "title d2";

              connect(this, SIGNAL(on_pushButton_clicked()), d2, SLOT()); // and the slot should be the function defined that adds a new tab in the tabWidget
              }

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

              //dialog1.h
              #ifndef DIALOG1_H
              #define DIALOG1_H

              #include <QDialog>
              #include <QTabWidget>

              namespace Ui {
              class Dialog1;
              }

              class Dialog1 : public QDialog
              {
              Q_OBJECT

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

              signals:
              void on_pushButton_clicked();

              private:
              Ui::Dialog1 *ui;
              };

              #endif // DIALOG1_H

              //and the function addNewTab is defined in dialog2.h
              //dialog2.h
              #ifndef DIALOG2_H
              #define DIALOG2_H

              #include <QDialog>2
              #include <QTabWidget>

              namespace Ui {
              class Dialog2;
              }

              class Dialog2 : public QDialog
              {
              Q_OBJECT

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

              private slots:
              void addNewTab(QWidget * page, QString & title)
              {
              QTabWidget *newTab = new QTabWidget;

                 // setCentralWidget(newTab);
                  newTab->addTab(page, title);
                  newTab->setTabsClosable(true);
              }
              

              signals:
              void on_pushButton_clicked();

              private:
              Ui::Dialog2 *ui;
              };

              #endif // DIALOG2_H@

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

                Why does Dialog1 create a Dialog2 instance ?
                Why does Dialog2 create a QTabWidget ?

                You are mixing together everything. If something done in Dialog1 should trigger something in MainWindow then it should not happen in Dialog2.

                You should do some sketches of what each widget of your application should do. Are you sure you need all these dialogs ?

                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
                  #27

                  thanks for your input. I have the impression that I'm mixing all. let's say dialog1 it's a window with some widgets in, and dialog2 it's a filter, or son of the dialog1.
                  all windows are opened in mainWindow in tabWidget.

                  as soon as dialog1.pushButton is trigged, the dialog2 opens in a new tab in mainWindow. this is what should happened.

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

                    Are you trying to create some sort of wizard ?

                    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
                      #29

                      no, just trying to understand how to open any dialog in tabWidget (in mainWindow). thanks

                      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