Results 1 to 3 of 3

Thread: create a Object by its name.

  1. #1
    Join Date
    Mar 2009
    Location
    Gansu,China
    Posts
    188
    Qt products
    Qt4
    Platforms
    Windows

    Default create a Object by its name.

    I have define many class,and their names are like this:
    Icon1,Icon2,Icon3,....,Icon1000;

    Now I want to know that how to create an object of them dynamicly by the digital in their names?
    For example,If I know 6,how I create the object of Icon6?
    Last edited by weixj2003ld; 10th August 2011 at 02:37. Reason: soryy

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: create a Object by its name.

    First thing if you are creating 1000 classes of Icon (like Icon1, Icon2....) then you should be doing something which is way out of the way. Rather you should be creating hierarchy of classes and objects of them.

    Second, the only option to create the object (IMO), with just knowing the digit in the class name is to create a switch statement with 1000 cases. I am sure no-body would like to write such thing, unless code automatically generated.

  3. #3
    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: create a Object by its name.

    If those classes inherited QObject, they could be marshalled by name.
    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.


Similar Threads

  1. How do I create an Object at runtime?
    By Cayan in forum Newbie
    Replies: 2
    Last Post: 28th June 2010, 07:01
  2. Replies: 1
    Last Post: 27th February 2010, 10:33
  3. Replies: 1
    Last Post: 1st February 2010, 15:13
  4. finding dynamically create object
    By abrou in forum Newbie
    Replies: 2
    Last Post: 5th March 2008, 21:17
  5. Can't create an object : initialisation problem ?
    By Nyphel in forum Qt Programming
    Replies: 5
    Last Post: 12th March 2007, 09:07

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.