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. How to invoke qml object from qt C
Forum Updated to NodeBB v4.3 + New Features

How to invoke qml object from qt C

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 1.1k 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.
  • H Offline
    H Offline
    houmingc
    wrote on last edited by
    #1

    I can't find any link on interacting QML objects from C++
    I need to change the rectangle color in qml from red to green. Please assist.

    @
    ---------------------h file

    signals:
    void redcolor();
    void greencolor();

    ---------------------cpp file
    QStateMachine machine;
    QState *group= new QState();
    group->setObjectName("MyGroup");
    QTimer timer;
    timer.setInterval(1250);
    timer.setSingleShot(true);
    QObject::connect(group,SIGNAL(entered()),&timer, SLOT(start()));

    QState *state1;
    QState *state2;

    state1=function1(emit redcolor;);
    state2=function2(emit greencolor;);

    }

    -------------------------------------qml

    Item{
    id:container
    width:300; height:300

          Rectangle{
                      id:rect
                      width:190; height:190
                      color: "red"
                   MouseArea{
                          id:mouseArea
                          anchors.fill: parent
                        }
                    onColorChanged?rect.color= green: rect.color=red;
         }
    

    }

    @

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

      Hi,

      Have a look at "this":http://qt-project.org/doc/qt-5/qtqml-cppintegration-interactqmlfromcpp.html document.

      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