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. Updating c++ data in Qml
Forum Updated to NodeBB v4.3 + New Features

Updating c++ data in Qml

Scheduled Pinned Locked Moved Solved General and Desktop
46 Posts 6 Posters 6.0k 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #13

    And you expect these two unrelated instances to communicate between different widgets from your UI ?

    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
    • D Offline
      D Offline
      dziko147
      wrote on last edited by
      #14

      @SGaist said in Updating c++ data in Qml:

      expect these two unrelated instances to communicate between different widgets from your UI ?

      no I mentioned that these two instances cause a problem.

      So can you suggest a way to do this !

      BTW UploadCSV is a QDialog , Backend is QObject .

      when I create instance in UploadCSV.h it cause problem !

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

        Review your application architecture. There's an issue with what is created where and how they interact with each other.

        You seem to have an issue with the proper composition of your various classes and GUI elements.

        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
        • D Offline
          D Offline
          dziko147
          wrote on last edited by
          #16

          @SGaist there no way to solve it ?

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

            Yes there is and was already suggested in your other threads. You need to properly create your objects hierarchy.

            You were creating a MainWidget object in your dialog trying to get data from it while it was in fact created by a different instance.

            You seem to reproduce a similar scheme here.

            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
            • D Offline
              D Offline
              dziko147
              wrote on last edited by
              #18

              @SGaist In my situation , when I would like to create an Backend instance in UploadCSV to emit signal .
              And create Backend instance in MainWindow to set a contextProperty .
              what should I do .
              Please :)

              KroMignonK 1 Reply Last reply
              0
              • D dziko147

                @SGaist In my situation , when I would like to create an Backend instance in UploadCSV to emit signal .
                And create Backend instance in MainWindow to set a contextProperty .
                what should I do .
                Please :)

                KroMignonK Offline
                KroMignonK Offline
                KroMignon
                wrote on last edited by
                #19

                @dziko147 said in Updating c++ data in Qml:

                In my situation , when I would like to create an Backend instance in UploadCSV to emit signal .
                And create Backend instance in MainWindow to set a contextProperty .
                what should I do .
                Please :)

                You should first explain why you think you have to create a Backend instance in UploadCSV?
                It is impossible to understand (for me) what is the purpose of this.
                And emitting a signal which is connected to nothing, results to nothing.

                It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  dziko147
                  wrote on last edited by
                  #20

                  @KroMignon in uploadcsv ui , i have a button . I want to emit clicked signal connected to a slot in backend which change data (see my code please) .

                  KroMignonK 1 Reply Last reply
                  0
                  • D dziko147

                    @KroMignon in uploadcsv ui , i have a button . I want to emit clicked signal connected to a slot in backend which change data (see my code please) .

                    KroMignonK Offline
                    KroMignonK Offline
                    KroMignon
                    wrote on last edited by
                    #21

                    @dziko147 said in Updating c++ data in Qml:

                    in uploadcsv ui , i have a button . I want to emit clicked signal connected to a slot in backend which change data (see my code please) .

                    Your code is incomprehensible!
                    Please learn C++ basics, like what are classes, class members, class methods and class instances.

                    I don't understand what is your problem, on click event the method status() instance back which is created in UploadCSV.cpp will be called and you should see a debug message on console.

                    I don't understand why you expect anything on QML side as this instance is not exposed to QML.

                    It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                    1 Reply Last reply
                    1
                    • D Offline
                      D Offline
                      dziko147
                      wrote on last edited by
                      #22

                      there is no one who did something like this ?

                      KroMignonK 1 Reply Last reply
                      0
                      • D dziko147

                        there is no one who did something like this ?

                        KroMignonK Offline
                        KroMignonK Offline
                        KroMignon
                        wrote on last edited by
                        #23

                        @dziko147 said in Updating c++ data in Qml:

                        there is no one who did something like this ?

                        Again, explain what you want to do, not what you have done.
                        Because what you have done don't made sense.

                        If you want to update the Backend instance back create in MainWindow on button click in UploadCSV.cpp, then you have to connect the click event with this instance, not create a new instance of Backend in UploadCSV.cpp.

                        It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                        1 Reply Last reply
                        0
                        • D Offline
                          D Offline
                          dziko147
                          wrote on last edited by
                          #24

                          @KroMignon if I understand you . I should create an MainWindow Instance in UploadCSV.cpp then I call the back defined in MainWindow ?
                          Is that ?

                          KroMignonK jsulmJ 2 Replies Last reply
                          0
                          • D dziko147

                            @KroMignon if I understand you . I should create an MainWindow Instance in UploadCSV.cpp then I call the back defined in MainWindow ?
                            Is that ?

                            KroMignonK Offline
                            KroMignonK Offline
                            KroMignon
                            wrote on last edited by
                            #25

                            @dziko147 said in Updating c++ data in Qml:

                            if I understand you . I should create an MainWindow Instance in UploadCSV.cpp then I call the back defined in MainWindow ?
                            Is that ?

                            No, you don't understand anything, and that is very bad :(
                            You have to connect the click signal from the UploadCSV instance to the back variable (which should be a class member ==> https://www.learncpp.com/cpp-tutorial/classes-and-class-members/) of the MainWindow instance.

                            And NOT create a new instance.

                            It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                            1 Reply Last reply
                            1
                            • D dziko147

                              @KroMignon if I understand you . I should create an MainWindow Instance in UploadCSV.cpp then I call the back defined in MainWindow ?
                              Is that ?

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

                              @dziko147 said in Updating c++ data in Qml:

                              Is that ?

                              No.
                              Why should UploadCSV create main window?!
                              Please read more carefully.

                              You should really learn what instances are! Two different instance are exactly that: two different instances/objects, they are NOT same.
                              If you create two instances of a class (lets name them A and B), then connect a slot from A to a signal, then do you expect that the slot in B will also be called if the signal is emitted? Yes or No?

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

                              D 1 Reply Last reply
                              0
                              • jsulmJ jsulm

                                @dziko147 said in Updating c++ data in Qml:

                                Is that ?

                                No.
                                Why should UploadCSV create main window?!
                                Please read more carefully.

                                You should really learn what instances are! Two different instance are exactly that: two different instances/objects, they are NOT same.
                                If you create two instances of a class (lets name them A and B), then connect a slot from A to a signal, then do you expect that the slot in B will also be called if the signal is emitted? Yes or No?

                                D Offline
                                D Offline
                                dziko147
                                wrote on last edited by dziko147
                                #27

                                @jsulm Sure No .

                                @KroMignon If I don't create MainWindow instance, how can i access to mainwindow variable from UploadCSV.

                                MainWindow *mymain=new MainWindow();
                                    connect(ui->parambtn_2, SIGNAL(clicked()),mymain->back, SLOT(status()),Qt::QueuedConnection);
                                
                                

                                this is what I think .
                                Correct me please :)

                                jsulmJ 1 Reply Last reply
                                0
                                • D dziko147

                                  @jsulm Sure No .

                                  @KroMignon If I don't create MainWindow instance, how can i access to mainwindow variable from UploadCSV.

                                  MainWindow *mymain=new MainWindow();
                                      connect(ui->parambtn_2, SIGNAL(clicked()),mymain->back, SLOT(status()),Qt::QueuedConnection);
                                  
                                  

                                  this is what I think .
                                  Correct me please :)

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

                                  @dziko147 said in Updating c++ data in Qml:

                                  If I don't create MainWindow instance, how can i access to mainwindow variable from UploadCSV.

                                  Don't create a SECOND MainWindow instance! Use the one you already have (you probably create it in main.cpp, right?)...

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

                                  D 1 Reply Last reply
                                  0
                                  • jsulmJ jsulm

                                    @dziko147 said in Updating c++ data in Qml:

                                    If I don't create MainWindow instance, how can i access to mainwindow variable from UploadCSV.

                                    Don't create a SECOND MainWindow instance! Use the one you already have (you probably create it in main.cpp, right?)...

                                    D Offline
                                    D Offline
                                    dziko147
                                    wrote on last edited by
                                    #29

                                    @jsulm Yes sure . so I use it ?

                                    jsulmJ 1 Reply Last reply
                                    0
                                    • D dziko147

                                      @jsulm Yes sure . so I use it ?

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

                                      @dziko147 said in Updating c++ data in Qml:

                                      so I use it ?

                                      Yes, the one you already have

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

                                      1 Reply Last reply
                                      0
                                      • D Offline
                                        D Offline
                                        dziko147
                                        wrote on last edited by
                                        #31

                                        @KroMignon Is this code correct ??

                                        I create a class member :

                                        class MainWindow : public QMainWindow
                                        {
                                            Q_OBJECT
                                        public:
                                            Backend *back;
                                        

                                        then in uploadCSV.cpp

                                          connect(ui->parambtn_2, SIGNAL(clicked()),MainWindow().back, SLOT(statuspican()),Qt::QueuedConnection);
                                        
                                        

                                        But still doesn't work !

                                        jsulmJ 1 Reply Last reply
                                        0
                                        • D dziko147

                                          @KroMignon Is this code correct ??

                                          I create a class member :

                                          class MainWindow : public QMainWindow
                                          {
                                              Q_OBJECT
                                          public:
                                              Backend *back;
                                          

                                          then in uploadCSV.cpp

                                            connect(ui->parambtn_2, SIGNAL(clicked()),MainWindow().back, SLOT(statuspican()),Qt::QueuedConnection);
                                          
                                          

                                          But still doesn't work !

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

                                          @dziko147 said in Updating c++ data in Qml:

                                          connect(ui->parambtn_2, SIGNAL(clicked()),MainWindow().back, SLOT(statuspican()),Qt::QueuedConnection);

                                          You're creating a new MainWindow instance in the connect.
                                          I give up...

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

                                          D 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