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] Defining own QML type - can i define method ?
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Defining own QML type - can i define method ?

Scheduled Pinned Locked Moved QML and Qt Quick
5 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.
  • S Offline
    S Offline
    sibislaw2
    wrote on last edited by
    #1

    Hi, i was wondering about how i can define own C++ methods for QML component.

    @
    class TimeModel : public QObject
    {
    Q_OBJECT
    Q_PROPERTY(int hour READ hour NOTIFY timeChanged)
    Q_PROPERTY(int minute READ minute NOTIFY timeChanged)
    ...
    @

    This is code example from documentation. Thereis defined properties, but i want to define method to which i will call later in QML code, like this:

    @TimeModel {
    id: tm
    }

    ..
    tm.someMethod()
    ..@

    I didnt found Q_METHOD() in qt. Anny suggestions ??

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

      There are 2 ways:

      • mark methods with Q_INVOKABLE
      • make them be public slots

      (Z(:^

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sibislaw2
        wrote on last edited by
        #3

        Ok, thanks. So both conditions are needed ?

        • mark methods with Q_INVOKABLE
        • make them be public slots

        Both of them ?

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

          No. Either one will work.

          (Z(:^

          1 Reply Last reply
          0
          • S Offline
            S Offline
            sibislaw2
            wrote on last edited by
            #5

            Ok, thanks. That worked.

            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