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. Connecting C++ signal to QML function with arguments

Connecting C++ signal to QML function with arguments

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

    Connecting a C++ signal to a QML function seems to work fine if the QML function has no arguments.
    But if the QML function has an argument, how can I connect a signal to it? What is the type of the argument? QVariant?

    1 Reply Last reply
    0
    • T Offline
      T Offline
      timoph
      wrote on last edited by
      #2

      name the parameters in your signal declaration, something like this

      @void mySignal(int value);@

      and you can get the parameter value by using that name. for example

      @
      connections {
      target: engine

      onMySignal: {
      console.log(value)
      }
      }
      @

      1 Reply Last reply
      0
      • L Offline
        L Offline
        ludde
        wrote on last edited by
        #3

        Thanks. Problem is, I need to connect the signal to the QML function from C++, since I don't know the name of the signal/function to connect until runtime.

        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