List of types (is it possible?)

  • Hi everybody!
    Is it possible make list that contains data types?
    @QMap<QString name, type t> typeList;
    ParentClass *vObject = new typeList.value("ClassName1");@

  • Yes and no.

    Yes, you can create a QMap<QString, std::type_info>.

    No, I see no way to invoke a static member or to instatiate an object using this list without a common base class or a factory.

    If your types already share QObject as the common base class you can use QMetaObject::newInstance() resp. QMetaObject::invokeMethod() provided that both, the constructor and the methods, are marked as Q_INVOKABLE.

    If your types qualify you can also use QMetaType::construct().

  • Thanks, Lukas!
    QMetaObject solves most part of the problems.

Log in to reply

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