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. Send variable value from .cpp to .qml
Qt 6.11 is out! See what's new in the release blog

Send variable value from .cpp to .qml

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 4 Posters 828 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
    d4n1
    wrote on last edited by
    #1

    Hello, I am collecting information from a gps (longitude and latitude) without problems. I represent this information in an lcdNumber, but I also want to send it to a .qml file to represent it in a map. After some tests I have not succeeded. Is there any simple way to do this? Do you have information about it?

    I am new to using qt and qml.

    Best regards

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

      Hi and welcome to devnet,

      There's a whole chapter dedicated to that in the documentation. It should help you get started.

      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
        d4n1
        wrote on last edited by
        #3

        Hi, I try but it doesn't work (QT 5.15.1 and MSVC2019).
        The error: module "io.qt.examples.backend" is not installed.
        I have tried some solutions that I have found without success. It seems to me that from version 5.15 that example should work.

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

          Can you show what your .pro file looks like ?

          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
          • JoeCFDJ Offline
            JoeCFDJ Offline
            JoeCFD
            wrote on last edited by JoeCFD
            #5

            one way to do it as follows:
            m_qmlAppEngine->rootContext()->setContextProperty( "lcdNumber", new lcdNumber() /* your class instance*/);
            define the properties with signal for example longitudeChanged() in lcdNumber and you can use lcdNumber in any qml file

            1 Reply Last reply
            1
            • D Offline
              D Offline
              d4n1
              wrote on last edited by
              #6

              Thanks to all, finally including in the .cpp,

                  connect(this, SIGNAL(<function_name>(QVariant)), obj, SLOT(<function_name>(QVariant)));
              

              works.

              I have put the headers in the .h and defined the operation in the .qml.

              Thank you!

              jsulmJ 1 Reply Last reply
              0
              • D d4n1

                Thanks to all, finally including in the .cpp,

                    connect(this, SIGNAL(<function_name>(QVariant)), obj, SLOT(<function_name>(QVariant)));
                

                works.

                I have put the headers in the .h and defined the operation in the .qml.

                Thank you!

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

                @d4n1 said in Send variable value from .cpp to .qml:

                connect(this, SIGNAL(<function_name>(QVariant)), obj, SLOT(<function_name>(QVariant)));

                Just a suggestion: you should switch to Qt5 connect syntax. It has one important advantage: if you do something wrong you will get compiler error during the build instead of a warning during application runtime.

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

                1 Reply Last reply
                1

                • Login

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