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 getting data from c++ to qml using QtQuickWidget
Forum Updated to NodeBB v4.3 + New Features

problem with getting data from c++ to qml using QtQuickWidget

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

    Hello ,
    Currently I displayed data from c++ to Qml QQuickwidget using signal and slots .
    I used this connection :
    QObject::connect(rootObject, SIGNAL(qmlVoltage()),
    this, SLOT(onSwitchVoltageClicked()),Qt::QueuedConnection);

    first problem: I would like to change this data from another Qdialog , when i change data there is no update in my qmlfile .

    Also I tried to display different qml file in the same Qquickwidget using signal and slots .
    Second problem: when i display the second qml file i get this error :

    TypeError: Cannot read property 'Voltage' of null .

    I will appreciate any suggestion .
    thank you

    mzimmersM 1 Reply Last reply
    0
    • D dziko147

      Hello ,
      Currently I displayed data from c++ to Qml QQuickwidget using signal and slots .
      I used this connection :
      QObject::connect(rootObject, SIGNAL(qmlVoltage()),
      this, SLOT(onSwitchVoltageClicked()),Qt::QueuedConnection);

      first problem: I would like to change this data from another Qdialog , when i change data there is no update in my qmlfile .

      Also I tried to display different qml file in the same Qquickwidget using signal and slots .
      Second problem: when i display the second qml file i get this error :

      TypeError: Cannot read property 'Voltage' of null .

      I will appreciate any suggestion .
      thank you

      mzimmersM Offline
      mzimmersM Offline
      mzimmers
      wrote on last edited by mzimmers
      #2

      @dziko147 there are a few steps involved in getting C++ data to your QML. Here's a good start to understanding this.

      Since you didn't post any code, we can't tell how much of this setup work you've done.

      JKSHJ 1 Reply Last reply
      0
      • mzimmersM mzimmers

        @dziko147 there are a few steps involved in getting C++ data to your QML. Here's a good start to understanding this.

        Since you didn't post any code, we can't tell how much of this setup work you've done.

        JKSHJ Offline
        JKSHJ Offline
        JKSH
        Moderators
        wrote on last edited by
        #3

        Hi @mzimmers, your link is missing; could you please edit it in?

        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

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

          @mzimmers thanks for your reply :)
          Currently i use this code :

          #ifndef BACKEND_H
          #define BACKEND_H

          #include <QObject>
          #include <QQmlEngine>

          class Backend : public QObject
          {
          Q_OBJECT
          Q_PROPERTY(QString directiontext READ getdirectiontext WRITE setdirectiontext NOTIFY directiontextChanged)
          QML_ELEMENT

          public:
          explicit Backend(QObject *parent = nullptr);
          QString getdirectiontext() {return m_directiontext;}
          ;}

          }
          

          //Setter methode //

          void setdirectiontext(QString text);
          

          signals:
          void directiontextChanged();

          private :
          QString m_directiontext;

          };

          #endif // BACKEND_H

          //Backend.cpp
          #include"backend.h"
          #include<QDebug>
          Backend::Backend(QObject *parent ) :QObject(parent)
          {
          m_directiontext="test direct";

          void Backend::setdirectiontext(QString text)
          {
          qDebug("signal direction called");
          if(m_directiontext == text)
          return;
          m_directiontext = text;
          emit directiontextChanged();
          }

          //MainWindow
          MainWindow::MainWindow(QWidget *parent) :
          QMainWindow(parent),
          m_ui(new Ui::MainWindow),

          {

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

          //In my Qml file :
          text: qsTr(cppObject.directiontext)

          //then i would like to change the data by :
          Backend back;
          QString Mode= ui->modecommande->currentText();
          qDebug() << Mode << "this is Mode select commande" ;
          back.setdirectiontext(Mode);

          I hope that my question is clear :)

          jsulmJ 1 Reply Last reply
          0
          • D dziko147

            @mzimmers thanks for your reply :)
            Currently i use this code :

            #ifndef BACKEND_H
            #define BACKEND_H

            #include <QObject>
            #include <QQmlEngine>

            class Backend : public QObject
            {
            Q_OBJECT
            Q_PROPERTY(QString directiontext READ getdirectiontext WRITE setdirectiontext NOTIFY directiontextChanged)
            QML_ELEMENT

            public:
            explicit Backend(QObject *parent = nullptr);
            QString getdirectiontext() {return m_directiontext;}
            ;}

            }
            

            //Setter methode //

            void setdirectiontext(QString text);
            

            signals:
            void directiontextChanged();

            private :
            QString m_directiontext;

            };

            #endif // BACKEND_H

            //Backend.cpp
            #include"backend.h"
            #include<QDebug>
            Backend::Backend(QObject *parent ) :QObject(parent)
            {
            m_directiontext="test direct";

            void Backend::setdirectiontext(QString text)
            {
            qDebug("signal direction called");
            if(m_directiontext == text)
            return;
            m_directiontext = text;
            emit directiontextChanged();
            }

            //MainWindow
            MainWindow::MainWindow(QWidget *parent) :
            QMainWindow(parent),
            m_ui(new Ui::MainWindow),

            {

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

            //In my Qml file :
            text: qsTr(cppObject.directiontext)

            //then i would like to change the data by :
            Backend back;
            QString Mode= ui->modecommande->currentText();
            qDebug() << Mode << "this is Mode select commande" ;
            back.setdirectiontext(Mode);

            I hope that my question is clear :)

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

            @dziko147 Please format your code properly, it makes it easier for others to read and understand it.

            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
              #6
              #ifndef BACKEND_H
              #define BACKEND_H
              
              #include <QObject>
              #include <QQmlEngine>
              
              class Backend : public QObject
              {
              Q_OBJECT
              Q_PROPERTY(QString directiontext READ getdirectiontext WRITE setdirectiontext NOTIFY directiontextChanged)
              QML_ELEMENT
              
              public:
              explicit Backend(QObject *parent = nullptr);
              QString getdirectiontext() {return m_directiontext;}
              ;}
              
              }
              //Setter methode //
              
              void setdirectiontext(QString text);
              signals:
              void directiontextChanged();
              
              private :
              QString m_directiontext;
              
              };
              
              #endif // BACKEND_H
              
              //Backend.cpp
              #include"backend.h"
              #include<QDebug>
              Backend::Backend(QObject *parent ) :QObject(parent)
              {
              m_directiontext="test direct";
              
              void Backend::setdirectiontext(QString text)
              {
              qDebug("signal direction called");
              if(m_directiontext == text)
              return;
              m_directiontext = text;
              emit directiontextChanged();
              }
              
              //MainWindow
              MainWindow::MainWindow(QWidget *parent) :
              QMainWindow(parent),
              m_ui(new Ui::MainWindow),
              
              {
              
              Backend back ;
              m_ui->quickWidget->rootContext()->setContextProperty("cppObject",&back);
              
              //In my Qml file :
              text: qsTr(cppObject.directiontext)
              
              //then i would like to change the data by :
              Backend back;
              QString Mode= ui->modecommande->currentText();
              qDebug() << Mode << "this is Mode select commande" ;
              back.setdirectiontext(Mode);
              
              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