Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-132493

Allow SIGNAL() and SLOT() to be used with QMetaObject::indexOfSignal() and QMetaObject::indexOfSlot()

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • P4: Low
    • None
    • 6.8
    • Core: Object Model
    • None
    • All

    Description

      This is in some way a follow-up to QTBUG-36861.

      I too think that generally a complementing `fromSlot` could help, but I think the core issue lies there:

      What I find odd is that there is basically no modern way to connect to a signal using its `QMetaMethod`: You have to use the `connect()` overload that takes both the signal and the slot as a QMetaMethod, which is fine by itself, but at the moment I can't find a modern way to get a `QMetaObject` for anything that I could connect to - except for using the string-based `indexOfMethod()` way. That is unfortunate.

      It is literally the only place in my code where I still have to use string-based method lookup.

      So instead of the already discussed `fromSlot()` which seems to be unavailable by design (moc doesn't report slot offsets?) I think the more viable solution would be to provide the messing overloads for the `connect()` function:

      QObject::connect(const QObject *sender, const QMetaMethod &signal, Functor functor);
      QObject::connect(const QObject *sender, const QMetaMethod &signal, const QObject *receiver, PointerToMemberFunction method);
      

      However (see comments) that proves to be difficult, as there is no immediate translation between a functor signature and the string based signature, so the connection would immantently loose the (static or runtime) type-safety.

      So as a final resort I'd like to propose an addition to the lookup functions to accept signatures provided by the usual `SIGNAL()` and `SLOT()` macros. That would make the usage of signal and slot names consistent between `connect()` and `indexOfSignal()`/`indexOfSlot()`. The addition would be similar to this:

          if (extract_code(slot) == QSLOT_CODE) {
              slot++;
          }
      #if QT7
          else {
              qWarning("QMetaObject::indexOfSlot: Use the SLOT or SIGNAL macro to lookup %s::%s",
                  priv->mobj->className(), slot);
              return -1;
          }
      #endif
      

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              cnn Qt Core & Network
              kamajii Sven Pauli
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes