Results 1 to 3 of 3

Thread: Is there any way to loop through all instances of a class?

  1. #1
    Join Date
    Apr 2011
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Is there any way to loop through all instances of a class?

    Hi Gurus,

    if I instantiated a class in multiple locations , is there any generic way I can loop through all the instances of that class?

    Thanks,

    RT

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Is there any way to loop through all instances of a class?

    No, there is not.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Is there any way to loop through all instances of a class?

    There is none prebuilt. But you could maintain a static list of instances in the class constructor.

    But depending on what you are trying to achieve and in what context this might be very bad design.

    It's usually much better to maintain lists of your instances on the scope the list is going to be used.

    For example a QGraphicsScene maintains a list of QGraphicsItems. As there can be multiple scenes in one application this is much better design than maintaining a static thus global list.

    HIH

    Johannes

Similar Threads

  1. Main loop thread loop communication
    By mcsahin in forum Qt Programming
    Replies: 7
    Last Post: 25th January 2011, 16:31
  2. how to run two instances of Qt simulator in windows xp.
    By hasnain in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 15th September 2010, 08:31
  3. Multiple program instances
    By scwizard in forum Qt Programming
    Replies: 13
    Last Post: 1st April 2007, 17:42
  4. accessing my own class-instances
    By mikro in forum Newbie
    Replies: 3
    Last Post: 11th July 2006, 00:10
  5. passing socket instances
    By smalls in forum Qt Programming
    Replies: 10
    Last Post: 24th January 2006, 22:36

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.