QMetaType::metaObjectForType



  • Hi I am trying to use QMetaType::metaObjectForType but am always getting a NULL return value and would be grateful if someone could explain why -

    Class declaration
    @
    class Widget : public QWidget
    {
    Q_OBJECT

    public:
    Q_INVOKABLE Widget(QWidget *parent=0);
    Widget(const Widget& other);
    ~Widget();
    };

    Q_DECLARE_METATYPE(Widget)
    @

    Class definition
    @
    const int WidgetTypeID = qRegisterMetaType<Widget>("Widget");

    Widget::Widget(QWidget *parent)
    : QWidget(parent)
    {
    }

    Widget::~Widget()
    {
    }

    Widget::Widget(const Widget& other)
    {
    Q_UNUSED(other)
    }
    @

    Usage
    @
    int id = QMetaType::type("Widget");
    const QMetaObject* baseMetaObject = QMetaType::metaObjectForType(id); -- Returns NULL

        QObject* o = (QObject*)(QMetaType::create(QMetaType::type("Widget"))); -- this works
    

    @


  • Moderators


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.