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. How to pass values from 2 differents dialogs to 1 dialog?
QtWS25 Last Chance

How to pass values from 2 differents dialogs to 1 dialog?

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 1.8k 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.
  • E Offline
    E Offline
    Eduardo12l
    wrote on last edited by Eduardo12l
    #1

    I want to add a new Dialog (Dialog2). I want that Dialog0 and the new Dialog2 can pass values to Dialog1. I only can pass values from one Dialog to another one, i mean one-to-one but no two-to-one. ¿How can i do it?

    Dialog0.cpp (only a fragment)

    void Dialog0::on_pushButton_clicked()
    {
        Dialog1 *v = new Dialog1(this, var);
        close();
        v->show();
    }
    
    

    Dialog0.h

    #ifndef DIALOG0_H
    #define DIALOG0_H
    
    #include <QDialog>
    #include <dialog1.h>
    namespace Ui {
    class Dialog0;
    }
    
    class Dialog0 : public QDialog
    {
        Q_OBJECT
    
    public:
        explicit Dialog0(QWidget *parent = 0);
        ~Dialog0();
        int var;
    private slots:
        void on_pushButton_clicked();
    
    private:
        Ui::Dialog0 *ui;
    };
    
    #endif // DIALOG0_H
    
    

    Dialog1.cpp

    #include "dialog1.h"
    #include "ui_dialog1.h"
    #include <dialog1.h>
    Dialog1::Dialog1(QWidget *parent, int var) :
        QDialog(parent),
        ui(new Ui::Dialog1), var(var)
    {
        ui->setupUi(this);
        ...
    }
    Dialog1::~Dialog1()
    {
        delete ui;
    }
    void Dialog1::on_pushButton_clicked()
    {
        ...
    }
    

    Dialog1.h

    #ifndef DIALOG1_H
    #define DIALOG1_H
    
    #include <QDialog>
    
    namespace Ui {
    class Dialog1;
    }
    
    class Dialog1 : public QDialog
    {
        Q_OBJECT
    
    public:
    
        explicit Dialog1(QWidget *parent = 0);
        Dialog1(QWidget *parent = 0, int var = 0);
        ~Dialog1();
        QString curso;
        int numero;
        int cont;
    private slots:
        void on_pushButton_clicked();
    
    private:
        int var;
        Ui::Dialog1 *ui;
    };
    
    #endif // DIALOG1_H
    
    
    joeQJ 1 Reply Last reply
    0
    • E Eduardo12l

      I want to add a new Dialog (Dialog2). I want that Dialog0 and the new Dialog2 can pass values to Dialog1. I only can pass values from one Dialog to another one, i mean one-to-one but no two-to-one. ¿How can i do it?

      Dialog0.cpp (only a fragment)

      void Dialog0::on_pushButton_clicked()
      {
          Dialog1 *v = new Dialog1(this, var);
          close();
          v->show();
      }
      
      

      Dialog0.h

      #ifndef DIALOG0_H
      #define DIALOG0_H
      
      #include <QDialog>
      #include <dialog1.h>
      namespace Ui {
      class Dialog0;
      }
      
      class Dialog0 : public QDialog
      {
          Q_OBJECT
      
      public:
          explicit Dialog0(QWidget *parent = 0);
          ~Dialog0();
          int var;
      private slots:
          void on_pushButton_clicked();
      
      private:
          Ui::Dialog0 *ui;
      };
      
      #endif // DIALOG0_H
      
      

      Dialog1.cpp

      #include "dialog1.h"
      #include "ui_dialog1.h"
      #include <dialog1.h>
      Dialog1::Dialog1(QWidget *parent, int var) :
          QDialog(parent),
          ui(new Ui::Dialog1), var(var)
      {
          ui->setupUi(this);
          ...
      }
      Dialog1::~Dialog1()
      {
          delete ui;
      }
      void Dialog1::on_pushButton_clicked()
      {
          ...
      }
      

      Dialog1.h

      #ifndef DIALOG1_H
      #define DIALOG1_H
      
      #include <QDialog>
      
      namespace Ui {
      class Dialog1;
      }
      
      class Dialog1 : public QDialog
      {
          Q_OBJECT
      
      public:
      
          explicit Dialog1(QWidget *parent = 0);
          Dialog1(QWidget *parent = 0, int var = 0);
          ~Dialog1();
          QString curso;
          int numero;
          int cont;
      private slots:
          void on_pushButton_clicked();
      
      private:
          int var;
          Ui::Dialog1 *ui;
      };
      
      #endif // DIALOG1_H
      
      
      joeQJ Offline
      joeQJ Offline
      joeQ
      wrote on last edited by
      #2

      @Eduardo12l Hi, friend, welcome.

      Where is your QDialog2 new ? Can you tell me or show some code for QDialog2 ?

      From your code snippet, I only know you new QDialog1 in Dialog0::button_click_function.

      Just do it!

      E 1 Reply Last reply
      0
      • joeQJ joeQ

        @Eduardo12l Hi, friend, welcome.

        Where is your QDialog2 new ? Can you tell me or show some code for QDialog2 ?

        From your code snippet, I only know you new QDialog1 in Dialog0::button_click_function.

        E Offline
        E Offline
        Eduardo12l
        wrote on last edited by Eduardo12l
        #3

        @joeQ Hi ^^ . This could be my Dialog2 but i dont know how to pass "nu" to Dialog1

        #include "dialog2.h"
        #include "ui_dialog2.h"
        
        Dialog2::Dialog2(QWidget *parent):
            QDialog(parent),
            ui(new Ui::Dialog2)  
        {
            ui->setupUi(this);
        }
        Dialog2::~Dialog2()
        {
            delete ui;
        }
        void Dialog2::on_pushButton_2_clicked()
        {
             ...
             Dialog1 *a = new Dialog1(this, nu);
             close();
             a->show();
        }
        
        joeQJ jsulmJ 2 Replies Last reply
        0
        • E Eduardo12l

          @joeQ Hi ^^ . This could be my Dialog2 but i dont know how to pass "nu" to Dialog1

          #include "dialog2.h"
          #include "ui_dialog2.h"
          
          Dialog2::Dialog2(QWidget *parent):
              QDialog(parent),
              ui(new Ui::Dialog2)  
          {
              ui->setupUi(this);
          }
          Dialog2::~Dialog2()
          {
              delete ui;
          }
          void Dialog2::on_pushButton_2_clicked()
          {
               ...
               Dialog1 *a = new Dialog1(this, nu);
               close();
               a->show();
          }
          
          joeQJ Offline
          joeQJ Offline
          joeQ
          wrote on last edited by
          #4

          @Eduardo12l

          Hi, from your code, you did it.

          Dialog1 *a = new Dialog1(this, nu); ///< you pass un to Dialog1

          can you show dialog2.h file ?

          I want to know where is you new dialog2 object ?

          Just do it!

          E 1 Reply Last reply
          0
          • E Eduardo12l

            @joeQ Hi ^^ . This could be my Dialog2 but i dont know how to pass "nu" to Dialog1

            #include "dialog2.h"
            #include "ui_dialog2.h"
            
            Dialog2::Dialog2(QWidget *parent):
                QDialog(parent),
                ui(new Ui::Dialog2)  
            {
                ui->setupUi(this);
            }
            Dialog2::~Dialog2()
            {
                delete ui;
            }
            void Dialog2::on_pushButton_2_clicked()
            {
                 ...
                 Dialog1 *a = new Dialog1(this, nu);
                 close();
                 a->show();
            }
            
            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @Eduardo12l Just use signals/slots, you can connect as many signal sender to one receiver as you want (it is n:m).

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            E 1 Reply Last reply
            2
            • jsulmJ jsulm

              @Eduardo12l Just use signals/slots, you can connect as many signal sender to one receiver as you want (it is n:m).

              E Offline
              E Offline
              Eduardo12l
              wrote on last edited by
              #6

              @jsulm But how can i pass data from Dialog 0 and Dialog2 to Dialog1. I know how to connect them but not how to pass data.

              jsulmJ 1 Reply Last reply
              0
              • joeQJ joeQ

                @Eduardo12l

                Hi, from your code, you did it.

                Dialog1 *a = new Dialog1(this, nu); ///< you pass un to Dialog1

                can you show dialog2.h file ?

                I want to know where is you new dialog2 object ?

                E Offline
                E Offline
                Eduardo12l
                wrote on last edited by
                #7

                @joeQ It has nothing because i dont know what to do

                #ifndef VENTANAS2_H
                #define VENTANAS2_H
                
                #include <QDialog>
                
                namespace Ui {
                class Ventanas2;
                }
                
                class Ventanas2 : public QDialog
                {
                   Q_OBJECT
                
                public:
                   explicit Ventanas2(QWidget *parent = 0);
                   ~Ventanas2();
                
                private:
                   Ui::Ventanas2 *ui;
                };
                
                #endif // VENTANAS2_H
                
                1 Reply Last reply
                0
                • E Eduardo12l

                  @jsulm But how can i pass data from Dialog 0 and Dialog2 to Dialog1. I know how to connect them but not how to pass data.

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by jsulm
                  #8

                  @Eduardo12l You connect a signal from Dialog0 to Dialog1 and you connect a signal from Dialog2 to Dialog1, that's all. You pass data as signal parameter:

                  class SignalSender: public QObject
                  {
                  Q_OBJECT
                  
                  signals:
                      void signal1(const QString &someData);
                   };
                  
                  class SignalReceiver: public QObject
                  {
                  Q_OBJECT
                  
                  public slots:
                      void doSomething(const QString &someData);
                  }
                  
                  SignalSender *sender = new SignalSender();
                  SignalReceiver *receiver = new SignalReceiver();
                  connect(sender, SIGNAL(signal1(QString)), receiver, SLOT(doSomething(QString)));
                  // then somewhere in SignalSender:
                  QString data = "some data";
                  emit signal1(data);
                  

                  Everything is described here: http://doc.qt.io/qt-5.9/signalsandslots.html

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  2

                  • Login

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