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

QMetaObject::constructorCount returns 0

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 5.11.3
    • Core: Object Model
    • None
    • Debian Buster, gcc gcc (Debian 8.3.0-6) 8.3.0
    • Linux/X11

    Description

      I have a simple QObject-derived class:

      class MyItem : public QObject {
        Q_OBJECT
        Q_PROPERTY(QString strfield READ strfield)
        Q_CLASSINFO("foo", "bar")
        QString m_strfield;
      public:
        explicit MyItem(QObject *parent = nullptr);
        MyItem(int, int, char *, QString);
        QString strfield() const \{ return m_strfield; }
      };
      

      which is registered with `qRegisterMetaType<MyItem*>();`

      later, in main.cpp I have the following code:

      for (int typeId = QMetaType::User;; typeId++) {
        if (!QMetaType::isRegistered(typeId)) break;
        qDebug() << "found metatype" << QMetaType::typeName(typeId);
        const QMetaObject* mo = QMetaType::metaObjectForType(typeId);
        qDebug() << "class info";
        for (int i = 0; i < mo->classInfoCount(); i++) {
          qDebug() << "classInfo" << mo->classInfo(i).name() << mo->classInfo(i).value();
        }
        qDebug() << "Constructors" << mo->constructorCount();
        for (int ctorIndex = 0; ctorIndex < mo->constructorCount(); ctorIndex++) {
          QMetaMethod ctor = mo->constructor(ctorIndex);
          qDebug() << "constructor" << ctor.name() << "signature" << ctor.methodSignature();
        }
        qDebug() << "Methods";
        for (int methodIndex = 0; methodIndex < mo->methodCount(); methodIndex++) {
          QMetaMethod method = mo->method(methodIndex);
          qDebug() << "method" << method.name() << "signature" << method.methodSignature(); 
        }
      }
      

      ClassInfo and methods are printed just fine, but constructorCount is always 0;

      How come?
      Any hints would be appreciated!

      Attachments

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

        Activity

          People

            thiago Thiago Macieira
            aol Andrey L
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes