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. [Solved] QtQuick Application recommended "To-Do"s
Forum Updated to NodeBB v4.3 + New Features

[Solved] QtQuick Application recommended "To-Do"s

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

    hello,

    can you give me some exercises on Qml and C++ binding or some examples, if you have some.
    i already did some binding with slots, but i want to do more than (or then, excuse my grammar) printing some data in a qml window.

    thank you!

    :)

    1 Reply Last reply
    0
    • O Offline
      O Offline
      onek24
      wrote on last edited by
      #2

      Hey,

      your Viewer has got a rootContext() and a rootObject(). Lets just take the rootObject:
      @QQuickView *view = new QQuickView();
      view->setSource(QUrl("YourQmlFile.qml"));
      QObject object = (QObject)view->rootObject();@

      The rootObject is your top-level object in qml and has got all other components as children. If you are searching for a children you should give it an objectName.
      @Rectangle {
      objectName: "myRectangle"
      // some code
      }@

      Now we search for our Rectangle using the function findChild().
      @QObject myObject = object->findChild<QObject>("myRectangle");
      if(object){
      // We got it :)
      }@

      Lets go ahead and set a property:
      @object->setProperty("propertyName", QVariant("someValue"));@

      It’s also easy to get a property:
      @QVariant ourProperty = object->property("propertyName");@

      You could use QMetaObject::invokeMethod to invoke a QML method.
      For example:
      @QQuickView *view = new QQuickView();
      QObject object = (QObject)view->rootObject();
      QMetaObject::invokeMethod(object, "nameOfYourQmlFunction");@

      If you want to pass parameters:
      @QMetaObject::invokeMethod(object, "nameOfYourQmlFunction", Q_ARG(QVariant, "valueToSend"))@

      You can replace the String with booleans or integers, QML transforms them to it’s required format. If you want to have some values returned you’ll need a Q_RETURN_ARG instead of the Q_ARG.
      Function in the Documentation:
      @bool QMetaObject::invokeMethod(QObject * obj, const char * member, Qt::ConnectionType type, QGenericReturnArgument ret, QGenericArgument val0 = QGenericArgument( 0 ), QGenericArgument val1 = QGenericArgument(), QGenericArgument val2 = QGenericArgument(), QGenericArgument val3 = QGenericArgument(), QGenericArgument val4 = QGenericArgument(), QGenericArgument val5 = QGenericArgument(), QGenericArgument val6 = QGenericArgument(), QGenericArgument val7 = QGenericArgument(), QGenericArgument val8 = QGenericArgument(), QGenericArgument val9 = QGenericArgument())[static]@

      For further informations i would recommend you to read:
      "Using QML Bindings in C++ Applications":http://qt-project.org/doc/qt-4.8/qtbinding.html
      "Interacting with QML Objects from C++":http://qt-project.org/doc/qt-5.0/qtqml/qtqml-cppintegration-interactqmlfromcpp.html
      "Calling Functions":http://qt-project.org/doc/qt-4.8/qtbinding.html#calling-functions
      "Receiving Signals":http://qt-project.org/doc/qt-4.8/qtbinding.html#receiving-signals
      "Supportet Datatypes":http://qt-project.org/doc/qt-4.8/qtbinding.html#supported-data-types

      Beside of that you can also provide a custom Cpp model to QML.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mititelud
        wrote on last edited by
        #3

        thank you.

        i find your post more helpful than what i could find on qt-project.org.

        off topic: i'm new on qt and forums and whatnot. if you can close this topic as solved, that would be great. :D

        :)

        1 Reply Last reply
        0
        • O Offline
          O Offline
          onek24
          wrote on last edited by
          #4

          You're welcome, glad i could help you.
          It is not possible to close a thread, but you could edit your mainpost and add a [Solved] in front of the threadname.

          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