Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. List of types (is it possible?)
Forum Updated to NodeBB v4.3 + New Features

List of types (is it possible?)

Scheduled Pinned Locked Moved C++ Gurus
3 Posts 2 Posters 1.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    qxoz
    wrote on last edited by
    #1

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

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

      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().

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        qxoz
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved