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 to QML signal function based syntax
Forum Updated to NodeBB v4.3 + New Features

Connecting to QML signal function based syntax

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 2 Posters 1.6k Views 2 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.
  • G Offline
    G Offline
    guy incognito
    wrote on last edited by
    #1

    Hi all,

    I'm trying to connect a QML signal to a C++ slot and want to use the function-based syntax:

    connect(sender, &Sender::valueChanged,  receiver, &Receiver::updateValue );
    

    Here is the explanation how to do it string-based and it works for me, but what would be the &Sender in this example?

    A 1 Reply Last reply
    0
    • G guy incognito

      Hi all,

      I'm trying to connect a QML signal to a C++ slot and want to use the function-based syntax:

      connect(sender, &Sender::valueChanged,  receiver, &Receiver::updateValue );
      

      Here is the explanation how to do it string-based and it works for me, but what would be the &Sender in this example?

      A Offline
      A Offline
      ambershark
      wrote on last edited by
      #2

      @guy-incognito The examples in that link both use the old style of connecting signals/slots using SIGNAL() and SLOT() macros.

      The style you posted is the new style. In this case &Sender::valueChanged is a pointer to a function valueChanged in a class (QObject dervied) called Sender.

      I'm not quite sure what your question is in order to give you more information.

      My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

      G 1 Reply Last reply
      1
      • A ambershark

        @guy-incognito The examples in that link both use the old style of connecting signals/slots using SIGNAL() and SLOT() macros.

        The style you posted is the new style. In this case &Sender::valueChanged is a pointer to a function valueChanged in a class (QObject dervied) called Sender.

        I'm not quite sure what your question is in order to give you more information.

        G Offline
        G Offline
        guy incognito
        wrote on last edited by
        #3

        @ambershark

        My question is, how would I connect the signal "qmlSignal" in the example to the slot "cppSlot" using the new style. For me it's not clear what the sender would be, because it's a signal from the QML file.

        A 1 Reply Last reply
        0
        • G guy incognito

          @ambershark

          My question is, how would I connect the signal "qmlSignal" in the example to the slot "cppSlot" using the new style. For me it's not clear what the sender would be, because it's a signal from the QML file.

          A Offline
          A Offline
          ambershark
          wrote on last edited by
          #4

          @guy-incognito So I'm not sure you can use the new style connect syntax with a QML object. The reason is you don't know what kind of object it is, just that it derives from QObject.

          For example, in the example you linked they get a pointer to the qml object with QObject *item = view.rootObject();. So all you have is a QObject. In this case QObject does not have a qmlSignal in it, so you cant just do connect(item, &QObject::qmlSignal, ...).

          I'm not sure if you're able to even get the object that was defined with qmlSignal so you won't be able to use the new style syntax.

          I'm new enough to qml that there may be a way to get that actual object. If there is, and let's call it MyQmlObject then you would just do something like:

          auto item = qobject_cast<MyQmlObject *>(view.rootObject());
          connect(item, MyQmlObject::qmlSignal, .....);
          

          If you can find a way to get that object type/definition then you can do it. If not you're going to have to use the old SIGNAL(), SLOT() style.

          My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

          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