Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. How can i pass data between Qwidgets forms?
Qt 6.11 is out! See what's new in the release blog

How can i pass data between Qwidgets forms?

Scheduled Pinned Locked Moved Solved C++ Gurus
16 Posts 4 Posters 5.8k Views 2 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.
  • FlotisableF Flotisable

    @Eduardo12l
    you need to copy the element of LunINI from Dialog2 one by one, since there is no syntax to set array directly.

    by the way, why not use a vector instead?

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

    @Flotisable If I use QVector it will work? What about QList?

    FlotisableF 1 Reply Last reply
    0
    • E Eduardo12l

      @Flotisable If I use QVector it will work? What about QList?

      FlotisableF Offline
      FlotisableF Offline
      Flotisable
      wrote on last edited by Flotisable
      #4

      @Eduardo12l
      QVector and QList both will work

      E 1 Reply Last reply
      1
      • FlotisableF Flotisable

        @Eduardo12l
        QVector and QList both will work

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

        @Flotisable Ok, I'm quite new at C++ . I have a problem yet in Dialog2.cpp
        This is my QList<int> L .This time im not using an array (LunINI), im using L.

        Dialog2.h

        public:
            explicit Dialog2(QWidget *parent = 0);
            Dialog2(QWidget *parent = 0, const QString curso = "", const int numero = 0);
            int n = 0;
            int LunINI[24];
            QList <int> L;
        

        Dialog3.h

        class Dialog3 : public QDialog
        {
            Q_OBJECT
        
        public:
            explicit Dialog3(QWidget *parent = 0);
            Dialog3(QWidget *parent = 0, QList<int> *L = 0);
            ~Dialog3();
        private:
            int LunINI[24];
            QList <int> L;
            Ui::Dialog3 *ui;
        };
        
        

        Dialog2.cpp

        void Dialog2::on_pushButton_clicked(){
            Dialog3 *v = new Dialog3(this, L); //ERROR C2664 "cannot convert parameter 2 from 'QList<int>'  to  'QList<int>* '"
            close();
            v->show();
        }
        

        Dialog3.cpp

        
        Dialog3::Dialog3(QWidget *parent, QList<int> *L) :
            QDialog(parent),
            ui(new Ui::Dialog3), L(*L)
        {
            ui->setupUi(this);
        }
        
        jsulmJ FlotisableF 2 Replies Last reply
        0
        • E Eduardo12l

          @Flotisable Ok, I'm quite new at C++ . I have a problem yet in Dialog2.cpp
          This is my QList<int> L .This time im not using an array (LunINI), im using L.

          Dialog2.h

          public:
              explicit Dialog2(QWidget *parent = 0);
              Dialog2(QWidget *parent = 0, const QString curso = "", const int numero = 0);
              int n = 0;
              int LunINI[24];
              QList <int> L;
          

          Dialog3.h

          class Dialog3 : public QDialog
          {
              Q_OBJECT
          
          public:
              explicit Dialog3(QWidget *parent = 0);
              Dialog3(QWidget *parent = 0, QList<int> *L = 0);
              ~Dialog3();
          private:
              int LunINI[24];
              QList <int> L;
              Ui::Dialog3 *ui;
          };
          
          

          Dialog2.cpp

          void Dialog2::on_pushButton_clicked(){
              Dialog3 *v = new Dialog3(this, L); //ERROR C2664 "cannot convert parameter 2 from 'QList<int>'  to  'QList<int>* '"
              close();
              v->show();
          }
          

          Dialog3.cpp

          
          Dialog3::Dialog3(QWidget *parent, QList<int> *L) :
              QDialog(parent),
              ui(new Ui::Dialog3), L(*L)
          {
              ui->setupUi(this);
          }
          
          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by jsulm
          #6

          @Eduardo12l You should use QVector if you're going to use it like an array as it is much more efficient for this than QList.

          Dialog3 *v = new Dialog3(this, L); //ERROR C2664 "cannot convert parameter 2 from 'QList<int>'  to  'QList<int>* '"
          

          that's because Dialog3() constructor takes a pointer:

          Dialog3 *v = new Dialog3(this, &L);
          

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

          E 1 Reply Last reply
          2
          • E Eduardo12l

            @Flotisable Ok, I'm quite new at C++ . I have a problem yet in Dialog2.cpp
            This is my QList<int> L .This time im not using an array (LunINI), im using L.

            Dialog2.h

            public:
                explicit Dialog2(QWidget *parent = 0);
                Dialog2(QWidget *parent = 0, const QString curso = "", const int numero = 0);
                int n = 0;
                int LunINI[24];
                QList <int> L;
            

            Dialog3.h

            class Dialog3 : public QDialog
            {
                Q_OBJECT
            
            public:
                explicit Dialog3(QWidget *parent = 0);
                Dialog3(QWidget *parent = 0, QList<int> *L = 0);
                ~Dialog3();
            private:
                int LunINI[24];
                QList <int> L;
                Ui::Dialog3 *ui;
            };
            
            

            Dialog2.cpp

            void Dialog2::on_pushButton_clicked(){
                Dialog3 *v = new Dialog3(this, L); //ERROR C2664 "cannot convert parameter 2 from 'QList<int>'  to  'QList<int>* '"
                close();
                v->show();
            }
            

            Dialog3.cpp

            
            Dialog3::Dialog3(QWidget *parent, QList<int> *L) :
                QDialog(parent),
                ui(new Ui::Dialog3), L(*L)
            {
                ui->setupUi(this);
            }
            
            FlotisableF Offline
            FlotisableF Offline
            Flotisable
            wrote on last edited by
            #7

            @Eduardo12l
            to add @jsulm , you can use const reference instead of pointer in your Dialog3's constructor

            this way, you don't need to use & and *operator, I think it will make it more readable in your code

            E 1 Reply Last reply
            0
            • jsulmJ jsulm

              @Eduardo12l You should use QVector if you're going to use it like an array as it is much more efficient for this than QList.

              Dialog3 *v = new Dialog3(this, L); //ERROR C2664 "cannot convert parameter 2 from 'QList<int>'  to  'QList<int>* '"
              

              that's because Dialog3() constructor takes a pointer:

              Dialog3 *v = new Dialog3(this, &L);
              
              E Offline
              E Offline
              Eduardo12l
              wrote on last edited by
              #8

              @jsulm Thx this time Qt doesn't show an error message

              1 Reply Last reply
              0
              • FlotisableF Flotisable

                @Eduardo12l
                to add @jsulm , you can use const reference instead of pointer in your Dialog3's constructor

                this way, you don't need to use & and *operator, I think it will make it more readable in your code

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

                @Flotisable I dont understand, Do you mean that should add "const" instead of &?

                I mean

                Dialog3 *v = new Dialog3 (this, **const** L )
                
                FlotisableF 1 Reply Last reply
                0
                • E Eduardo12l

                  @Flotisable I dont understand, Do you mean that should add "const" instead of &?

                  I mean

                  Dialog3 *v = new Dialog3 (this, **const** L )
                  
                  FlotisableF Offline
                  FlotisableF Offline
                  Flotisable
                  wrote on last edited by Flotisable
                  #10

                  @Eduardo12l
                  no, I mean

                  Dialog3::Dialog3( QWidget *parent, const QList<int> &L ) :
                      QDialog( parent ), ui( new Ui::Dialog3 ), L( L )
                  

                  and

                  Dialog3 *v = new Dialog3( this, L );
                  
                  E 1 Reply Last reply
                  2
                  • FlotisableF Flotisable

                    @Eduardo12l
                    no, I mean

                    Dialog3::Dialog3( QWidget *parent, const QList<int> &L ) :
                        QDialog( parent ), ui( new Ui::Dialog3 ), L( L )
                    

                    and

                    Dialog3 *v = new Dialog3( this, L );
                    
                    E Offline
                    E Offline
                    Eduardo12l
                    wrote on last edited by
                    #11

                    @Flotisable It doesnt work but anyway thx ^^

                    jsulmJ 1 Reply Last reply
                    0
                    • E Eduardo12l

                      @Flotisable It doesnt work but anyway thx ^^

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

                      @Eduardo12l What does not work? What is the error?

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

                      E 1 Reply Last reply
                      0
                      • jsulmJ jsulm

                        @Eduardo12l What does not work? What is the error?

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

                        @jsulm What Flotisable says doesnt work. The code is below:

                        Dialog2.h

                        public:
                            explicit Dialog2(QWidget *parent = 0);
                            Dialog2(QWidget *parent = 0, const QString curso = "", const int numero = 0);
                            int n = 0;
                            int LunINI[24];
                            QList<int> L;
                            ~Dialog2();
                        

                        Dialog3.h:

                        public:
                        
                            explicit Dialog3(QWidget *parent = 0);
                            Dialog3(QWidget *parent = 0, const QList<int> &L=0); // ERROR C2440: Cannot convert from 'INT' to 'const QList<int>&'
                            ~Dialog3();
                        
                        private:
                            int LunINI[24];
                            QList <int> L;
                            Ui::Dialog3 *ui;
                        

                        Dialog2.cpp

                        void Dialog2::on_pushButton_clicked(){
                            Dialog3 *v = new Dialog3(this, L); 
                            close();
                            v->show();
                        }
                        

                        Dialog3.cpp

                        Dialog3::Dialog3(QWidget *parent, const QList<int> &L) :
                            QDialog(parent),
                            ui(new Ui::Dialog3), L(L)
                        {
                            ui->setupUi(this);
                        }
                        
                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #14

                          Hi,

                          You can't assign 0 to QList container. That's the error. You have to assign it an empty QList value if you want a default value for it.

                          On a side note, the common pattern is to have the parent parameter as the last in the constructor.

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

                          E 1 Reply Last reply
                          0
                          • SGaistS SGaist

                            Hi,

                            You can't assign 0 to QList container. That's the error. You have to assign it an empty QList value if you want a default value for it.

                            On a side note, the common pattern is to have the parent parameter as the last in the constructor.

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

                            @SGaist Thx but How can i assign an empty QList value?

                            FlotisableF 1 Reply Last reply
                            0
                            • E Eduardo12l

                              @SGaist Thx but How can i assign an empty QList value?

                              FlotisableF Offline
                              FlotisableF Offline
                              Flotisable
                              wrote on last edited by
                              #16

                              @Eduardo12l
                              since you have overloaded constructor, you don't need to give L a default value.
                              if you want, you can use

                                Dialog3( QWidget *parent = 0, const QList<int> &L = QList<int>() )
                              

                              QList<int>() will construct a QList<int> instance with empty value.

                              for what @SGaist says, you can modify the constructor this way

                              Dialog3( const QList<int> &L = QList<int>(), QWidget *parent = 0 )
                              

                              as I have said, you don't need to set a default value for L, so

                              Dialog3( const QList<int> &L, QWidget *parent = 0 )
                              

                              is enough

                              1 Reply Last reply
                              4

                              • Login

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