Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. problem with updating c++ data in a QML file
Forum Updated to NodeBB v4.3 + New Features

problem with updating c++ data in a QML file

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
6 Posts 4 Posters 499 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.
  • D Offline
    D Offline
    dziko147
    wrote on last edited by dziko147
    #1

    Hello , I want to update displayed data in Qml from C++ classes .
    So what I did is :

    1/ set a Contextproperty

        m_ui->quickWidget->rootContext()->setContextProperty("cppObject",&back);
    
    

    2/ create signal/slot

    connect(this, SIGNAL(directchange(QString)),&back, SLOT(Directchanged(QString)),Qt::QueuedConnection);
    

    3/ emit signal

    Mode=    ui->modecommande->currentText();
        qDebug() << Mode << "this is Mode select commande" ;
    
    
      emit directchange(Mode);
    
    

    4/ the slot :

    void Backend::Directchanged(QString text)
    {
        qDebug() << "text recu de commande " << text;
    
    
        setdirectiontext(text);
        qDebug() << "currently m-direct "<< m_directiontext; // here I get the exact QString Value 
    
    
    }
    

    in m_directiontext; I get the exact value but the QmlFile doesn't update the value

    KroMignonK 1 Reply Last reply
    0
    • D dziko147

      Hello , I want to update displayed data in Qml from C++ classes .
      So what I did is :

      1/ set a Contextproperty

          m_ui->quickWidget->rootContext()->setContextProperty("cppObject",&back);
      
      

      2/ create signal/slot

      connect(this, SIGNAL(directchange(QString)),&back, SLOT(Directchanged(QString)),Qt::QueuedConnection);
      

      3/ emit signal

      Mode=    ui->modecommande->currentText();
          qDebug() << Mode << "this is Mode select commande" ;
      
      
        emit directchange(Mode);
      
      

      4/ the slot :

      void Backend::Directchanged(QString text)
      {
          qDebug() << "text recu de commande " << text;
      
      
          setdirectiontext(text);
          qDebug() << "currently m-direct "<< m_directiontext; // here I get the exact QString Value 
      
      
      }
      

      in m_directiontext; I get the exact value but the QmlFile doesn't update the value

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

      @dziko147 where is back defined?

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

      SGaistS 1 Reply Last reply
      0
      • KroMignonK KroMignon

        @dziko147 where is back defined?

        SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @KroMignon based on his other thread I would say locally 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

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

          @KroMignon @SGaist No . Back is a Global variable defined in command.h (the headers where the connect is defined) .

          jsulmJ KroMignonK 2 Replies Last reply
          0
          • D dziko147

            @KroMignon @SGaist No . Back is a Global variable defined in command.h (the headers where the connect is defined) .

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

            @dziko147 said in problem with updating c++ data in a QML file:

            Back is a Global variable

            Global variables should be avoided as much as possible. Usually they are not needed and are a sign for bad design.

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

            1 Reply Last reply
            0
            • D dziko147

              @KroMignon @SGaist No . Back is a Global variable defined in command.h (the headers where the connect is defined) .

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

              @dziko147 said in problem with updating c++ data in a QML file:

              No . Back is a Global variable defined in command.h (the headers where the connect is defined) .

              Global variable defined in header sounds strange to me.
              And, as @jsulm already wrote, in C++ there is no good reason to use global variable... In C it may be used, but in C++ avoid it!

              I don't know what are your skills in programming, but you don't seems to be an experimented programmer.
              Why do you not start with Qt examples and try to understand how it works?
              Then start to modify it to adapt it to your needs.

              Please take time to read this, at least: https://doc.qt.io/qt-5/qtqml-cppintegration-interactqmlfromcpp.html

              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
              2

              • Login

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