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

Missing useful overload for QObject::connect

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • None
    • Core: Object Model
    • None

    Description

      I really miss an overload for `QObject::connect` with the following signature:

      QObject::connect(const QObject *sender, const QMetaMethod &signal, Functor functor)

      I would propose a diff but I'm not familiar in this code..

      My example is that I am wanting to monitor a named set of properties by connecting to these properties' notify signals:

       

      #include <QCoreApplication>
      #include <QMetaProperty>
      #include <QDebug>
      void observeProperties(QObject *object) {
          auto *mo = object->metaObject();
          for (int i = mo->propertyOffset(); i < mo->propertyCount(); ++i) {
              auto prop = mo->property(i);
              if (QString::fromLatin1(prop.name()).startsWith("observeMe")) {
                  qWarning() << "found prop" << prop.name();
                  QObject::connect(object, prop.notifySignal(), []() {
                      // No such overload
                  });
              }
          }
      }
      class Foo : public QObject {
          Q_OBJECT
          Q_PROPERTY(bool observeMePlease MEMBER m_please NOTIFY pleaseChanged)
      public:
          using QObject::QObject;
       
      signals:
          void pleaseChanged();
       
      private:
          bool m_please{false};
      };
      int main(int argc, char **argv) {
          QCoreApplication app(argc, argv);
       
          Foo foo;
          observeProperties(&foo); 
      }
      #include "main.moc"
      

       

       

      Attachments

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

        Activity

          People

            thiago Thiago Macieira
            andrhans Andreas Aardal Hanssen
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes