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. Transfer Data Between Two Forms
Forum Updated to NodeBB v4.3 + New Features

Transfer Data Between Two Forms

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 497 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.
  • S Offline
    S Offline
    Sekhar
    wrote on last edited by koahnig
    #1

    This is my code:

    send.h :

    #ifndef SEND_H
    #define SEND_H
    
    #include <QMainWindow>
    
    namespace Ui {
    class send;
    }
    
    class send : public QMainWindow
    {
        Q_OBJECT
    
    public:
        explicit send(QWidget *parent = 0);
        ~send();
    
    private slots:
        void on_pushButton_clicked();
        void showReceiveForm();
    
    signals:
        void newTextEntered(const QString &text);
    
    private:
        Ui::send *ui;
    };
    
    #endif // SEND_H
    

    send.cpp :

    #include "send.h"
    #include "ui_send.h"
    
    #include "chaild.h"
    #include "ui_chaild.h"
    
    send::send(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::send)
    {
        ui->setupUi(this);
    }
    
    send::~send()
    {
        delete ui;
    }
    
    void send::on_pushButton_clicked()
    {
       emit newTextEntered(ui->lineEdit->text());
    
        chaild ss;
        ss.show();
        ss.exec();
    }
    

    chaild.h :

    #ifndef CHAILD_H
    #define CHAILD_H
    
    #include <QDialog>
    
    namespace Ui {
    class chaild;
    }
    
    class chaild : public QDialog
    {
        Q_OBJECT
    
    public:
        QString ss;
        explicit chaild(QWidget *parent = 0);
        ~chaild();
    
    private slots:
        void on_spinBox_valueChanged(int arg1);
    
    public slots:
        void onNewTextEntered(const QString &text);
    
    private:
        Ui::chaild *ui;
    };
    

    chaild.cpp :

    #include "chaild.h"
    #include "ui_chaild.h"
    
    #include "send.h"
    #include "ui_send.h"
    
    chaild::chaild(QWidget *parent) :
        QDialog(parent),
        ui(new Ui::chaild)
    
    {
        ui->setupUi(this);
    
        send st;
    
        connect(&st,SIGNAL(newTextEntered(QString)),this,SLOT(onNewTextEntered(QString)));
    }
    
    chaild::~chaild()
    {
        delete ui;
    }
    
    void chaild::on_spinBox_valueChanged(int age)
    {
         ui->spinBox->setValue(age);
    }
    
    void chaild::onNewTextEntered(const QString &text)
    {
        // Adding a new item to the list widget
        ui->textEdit->setText(text);
    }
    

    please tell me how to pass the data from send form to chaild form

    [edit: koahnig, code tags introduced]

    K E 2 Replies Last reply
    0
    • S Sekhar

      This is my code:

      send.h :

      #ifndef SEND_H
      #define SEND_H
      
      #include <QMainWindow>
      
      namespace Ui {
      class send;
      }
      
      class send : public QMainWindow
      {
          Q_OBJECT
      
      public:
          explicit send(QWidget *parent = 0);
          ~send();
      
      private slots:
          void on_pushButton_clicked();
          void showReceiveForm();
      
      signals:
          void newTextEntered(const QString &text);
      
      private:
          Ui::send *ui;
      };
      
      #endif // SEND_H
      

      send.cpp :

      #include "send.h"
      #include "ui_send.h"
      
      #include "chaild.h"
      #include "ui_chaild.h"
      
      send::send(QWidget *parent) :
          QMainWindow(parent),
          ui(new Ui::send)
      {
          ui->setupUi(this);
      }
      
      send::~send()
      {
          delete ui;
      }
      
      void send::on_pushButton_clicked()
      {
         emit newTextEntered(ui->lineEdit->text());
      
          chaild ss;
          ss.show();
          ss.exec();
      }
      

      chaild.h :

      #ifndef CHAILD_H
      #define CHAILD_H
      
      #include <QDialog>
      
      namespace Ui {
      class chaild;
      }
      
      class chaild : public QDialog
      {
          Q_OBJECT
      
      public:
          QString ss;
          explicit chaild(QWidget *parent = 0);
          ~chaild();
      
      private slots:
          void on_spinBox_valueChanged(int arg1);
      
      public slots:
          void onNewTextEntered(const QString &text);
      
      private:
          Ui::chaild *ui;
      };
      

      chaild.cpp :

      #include "chaild.h"
      #include "ui_chaild.h"
      
      #include "send.h"
      #include "ui_send.h"
      
      chaild::chaild(QWidget *parent) :
          QDialog(parent),
          ui(new Ui::chaild)
      
      {
          ui->setupUi(this);
      
          send st;
      
          connect(&st,SIGNAL(newTextEntered(QString)),this,SLOT(onNewTextEntered(QString)));
      }
      
      chaild::~chaild()
      {
          delete ui;
      }
      
      void chaild::on_spinBox_valueChanged(int age)
      {
           ui->spinBox->setValue(age);
      }
      
      void chaild::onNewTextEntered(const QString &text)
      {
          // Adding a new item to the list widget
          ui->textEdit->setText(text);
      }
      

      please tell me how to pass the data from send form to chaild form

      [edit: koahnig, code tags introduced]

      K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      @Sekhar

      Hi and welcome to devnet forums

      I would suggest to you to have a look to the different examples for instance this http://doc.qt.io/qt-5/qtwidgets-dialogs-standarddialogs-example.html

      The problem you are generating is that these dialogs cross-dependencies.

      send is derived from QMainWindow which would typically exist the whole time. However, you are generating a local copy in your constructor of chaild:

      chaild::chaild(QWidget *parent) :
          QDialog(parent),
          ui(new Ui::chaild)
      
      {
          ui->setupUi(this);
      
          send st;
      
          connect(&st,SIGNAL(newTextEntered(QString)),this,SLOT(onNewTextEntered(QString)));
      }
      

      Basically the send object is deleted immediately after the connect statement since the local object gets out of focus.

      in send you do it basically the other way around:

      void send::on_pushButton_clicked()
      {
         emit newTextEntered(ui->lineEdit->text());    // sending the signal with information 
      
          chaild ss;          // now you create the obejct where you expect to receive the signal
          ss.show();
          ss.exec();
      }
      

      You are sending a signal to something that does not yet exist.

      I think best is with the example code given above, you can start doing modifications and therefore find out more about the different strategies. Also other examples might help you.

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

      1 Reply Last reply
      1
      • S Sekhar

        This is my code:

        send.h :

        #ifndef SEND_H
        #define SEND_H
        
        #include <QMainWindow>
        
        namespace Ui {
        class send;
        }
        
        class send : public QMainWindow
        {
            Q_OBJECT
        
        public:
            explicit send(QWidget *parent = 0);
            ~send();
        
        private slots:
            void on_pushButton_clicked();
            void showReceiveForm();
        
        signals:
            void newTextEntered(const QString &text);
        
        private:
            Ui::send *ui;
        };
        
        #endif // SEND_H
        

        send.cpp :

        #include "send.h"
        #include "ui_send.h"
        
        #include "chaild.h"
        #include "ui_chaild.h"
        
        send::send(QWidget *parent) :
            QMainWindow(parent),
            ui(new Ui::send)
        {
            ui->setupUi(this);
        }
        
        send::~send()
        {
            delete ui;
        }
        
        void send::on_pushButton_clicked()
        {
           emit newTextEntered(ui->lineEdit->text());
        
            chaild ss;
            ss.show();
            ss.exec();
        }
        

        chaild.h :

        #ifndef CHAILD_H
        #define CHAILD_H
        
        #include <QDialog>
        
        namespace Ui {
        class chaild;
        }
        
        class chaild : public QDialog
        {
            Q_OBJECT
        
        public:
            QString ss;
            explicit chaild(QWidget *parent = 0);
            ~chaild();
        
        private slots:
            void on_spinBox_valueChanged(int arg1);
        
        public slots:
            void onNewTextEntered(const QString &text);
        
        private:
            Ui::chaild *ui;
        };
        

        chaild.cpp :

        #include "chaild.h"
        #include "ui_chaild.h"
        
        #include "send.h"
        #include "ui_send.h"
        
        chaild::chaild(QWidget *parent) :
            QDialog(parent),
            ui(new Ui::chaild)
        
        {
            ui->setupUi(this);
        
            send st;
        
            connect(&st,SIGNAL(newTextEntered(QString)),this,SLOT(onNewTextEntered(QString)));
        }
        
        chaild::~chaild()
        {
            delete ui;
        }
        
        void chaild::on_spinBox_valueChanged(int age)
        {
             ui->spinBox->setValue(age);
        }
        
        void chaild::onNewTextEntered(const QString &text)
        {
            // Adding a new item to the list widget
            ui->textEdit->setText(text);
        }
        

        please tell me how to pass the data from send form to chaild form

        [edit: koahnig, code tags introduced]

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

        please tell me how to pass the data from send form to chaild form

        • How do you think about to take a bit more data modelling and corresponding presentation aspects into account?
        • Would you like to clarify the amount of desired data exchange at these places?
        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