Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Is it possible to access different objects (made by the same class) by substituting the name of the object in run time?

Is it possible to access different objects (made by the same class) by substituting the name of the object in run time?

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 496 Views
  • 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.
  • M Offline
    M Offline
    mohmo
    wrote on last edited by
    #1

    hey bros,
    I have a class or structure and i made some objects by this class(structure) as below:

    class myclass{
    int a;
    string b;
    float c;
    ...
    };
    myclass obj1,obj2,obj3,...,obj100; //making objects

    as you know i can use datamembers of all objects:
    obj1.a,
    obj1.b,
    obj1.c,
    ...

    i need a function or something like that to access all objects just by changing the name in run time, like:
    func(string str) { //str will be "obj1" or "obj2" or "obj3" or ...
    str.a=10;
    str.string="hello";
    ...
    }
    i know that a solution to define an array of objects and sweep on them by changing the index like:
    myclass obj [100];

    But i need to use names or string to substitute the object name.
    Thanks a lot.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Asperamanca
      wrote on last edited by
      #2

      If what you are looking for is "Access an object by name", you can use QHash or QMap, use a string as key and your object type as value.

      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