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 do I interact with QML from C++ in QtQuick 2.0
Forum Updated to NodeBB v4.3 + New Features

How do I interact with QML from C++ in QtQuick 2.0

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

    Let's say that we have a very simple QML file, like this one:

    @import QtQuick 2.0

    Rectangle {
    width: 800
    height: 600
    color: '#000'

    Text {
        text: qsTr("Hi all")
        anchors.centerIn: parent
    }
    

    }
    @

    The QML File is loaded with the QtQuick2ApplicationViewer helper class, like this:
    @QtQuick2ApplicationViewer viewer;
    viewer.setMainQmlFile(QStringLiteral("qml/MyApp/Login/Window.qml"));
    viewer.showFullScreen();
    @

    How should I proceed, if for example I would like to change the Rectangle's color to white, from C++. My guess was:
    @QQuickItem *window = viewer.rootObject();
    window->setProperty("color", "#fff");
    @
    But all that does is the following compiler error:
    @invalid use of incomplete type 'struct QQuickItem'
    forward declaration of 'struct QQuickItem'
    @

    1 Reply Last reply
    0
    • H Offline
      H Offline
      hipersayan_x
      wrote on last edited by
      #2

      You forgot the:

      @
      #include <QQuickItem>
      @

      before the use.

      1 Reply Last reply
      0
      • I Offline
        I Offline
        Itehnological
        wrote on last edited by
        #3

        Yhea. Didn't noticed I was missing that library. I spent a whole day digging on why that doesn't work. Thanks a lot!

        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