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. Change property value from c++
QtWS25 Last Chance

Change property value from c++

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
6 Posts 2 Posters 1.0k Views
  • 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.
  • w00t1234W Offline
    w00t1234W Offline
    w00t1234
    wrote on last edited by w00t1234
    #1

    Hi guys i need some help.

    How to change QML property value from c++ ?

    //main.cpp
    QQmlContext *ctx = engine.rootContext();
    ctx->setContextProperty("control",&allofthem);
    ctx->setProperty("text","Qt Everywhere");
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    
    //main.qml
    property string text
    .
    .
    .
    console.log(text)
    

    Result
    alt text

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      @w00t1234 You should set the property after loading the QML.

      157

      w00t1234W 1 Reply Last reply
      0
      • p3c0P p3c0

        @w00t1234 You should set the property after loading the QML.

        w00t1234W Offline
        w00t1234W Offline
        w00t1234
        wrote on last edited by
        #3

        @p3c0 said in Change property value from c++:

        @w00t1234 You should set the property after loading the QML.

        It's not work

        1 Reply Last reply
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          When are you printing the text? Use onTextChanged signal handler and print the text there.

          157

          w00t1234W 1 Reply Last reply
          0
          • p3c0P p3c0

            When are you printing the text? Use onTextChanged signal handler and print the text there.

            w00t1234W Offline
            w00t1234W Offline
            w00t1234
            wrote on last edited by
            #5

            @p3c0 said in Change property value from c++:

            When are you printing the text? Use onTextChanged signal handler and print the text there.

            Please example

            1 Reply Last reply
            0
            • p3c0P Offline
              p3c0P Offline
              p3c0
              Moderators
              wrote on last edited by
              #6

              Can you post your QML file ?

              157

              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