Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Qt Quick and C - different ways of linking QML and C/C++

Qt Quick and C - different ways of linking QML and C/C++

Scheduled Pinned Locked Moved Mobile and Embedded
2 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
    marcin100
    wrote on last edited by
    #1

    Hi,

    Could someone list different ways of linking a QML object's action with the C/C++ code behind. I have done some reading, most confusing to me and still cannot get a good grasp on this.

    For example:
    A QML defined button (via QtQuick 1.1 / Qt 4.8) is pressed on the touchscreen (or clicked with a mouse).
    This action should call a C/C++ function in the .cpp file

    Is there only one way of achieving this or many? (code examples would be greatly appreciated)
    What are the different ways, if any?
    What are the reasons for these different ways, if any?

    Thank you!

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      You need to expose a QObject to QML context. Then you can run any method marked as Q_INVOKABLE and modify any Q_PROPERTYies that it has.

      Another option is to inherit from QQuickItem (QDeclarativeItem in your case) and expose methods there (same story: Q_INOVKABLE, QPROPERTY).

      Check out my CCF project - it's probably to complicated as an example, but there you go. qmlRegisterType lines register custom kids of QQuickItem, while lines 69-73 register standard QObjects. You can find base classes for those objects in "the repo":https://github.com/sierdzio/closecombatfree/tree/master/src.

      (Z(:^

      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