Results 1 to 8 of 8

Thread: Dynamic objects without identifier...

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Dynamic objects without identifier...

    QHash<int, QWidget*> and qobject_cast to determine the type.
    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.


  2. #2
    Join Date
    Jul 2009
    Location
    Dundee, United Kingdom
    Posts
    18
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Dynamic objects without identifier...

    Hi,
    Thanks for your reply. I've decided to use a QObjectList which I populate in the if statements, where additionally I set the proper object names used later to identify the object "type" (image, string etc.). Works pretty well.

    Regards,
    Bill

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

    Default Re: Dynamic objects without identifier...

    It might be better to use QList<QWidget*> - it's better for you than QList<QObject*> because you can use the widget interface without any casting. If you want to stick with QObjectList, then you don't need it at all - at any time you can call QObject::children() on the parent widget (or the layout - you'd have to check that out) that will return you a QObjectList of its children.
    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.


  4. #4
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: Dynamic objects without identifier...

    QList<QString, QMetaObject>. Store the classes meta objects and then use QMetaObject::newInstance to create new instances.
    It's nice to be important but it's more important to be nice.

  5. #5
    Join Date
    Jul 2009
    Location
    Dundee, United Kingdom
    Posts
    18
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Dynamic objects without identifier...

    Hi,
    Thanks for the QMetaObject hint - I'll look at it in detail...
    Another problem I have is that I create an object and add it to a QScrollArea like this:
    Qt Code:
    1. scrollAreaWidgetContents->layout()->addWidget(date);
    To copy to clipboard, switch view to plain text mode 

    What would be the best way to remove objects from the QScrollArea, which have a pointer stored in a QList<QWidget*>?
    I've tried
    Qt Code:
    1. for(int i=0;i<formElements.length();++i) scrollAreaWidgetContents->layout()->removeWidget(formElements.at(i));
    To copy to clipboard, switch view to plain text mode 
    but end up with a segfault.

    Thanks for your help,
    Reagards,
    Bill

  6. #6
    Join Date
    Jul 2009
    Location
    Dundee, United Kingdom
    Posts
    18
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Dynamic objects without identifier...

    I think I found a solution.
    After a bit of RTFM,
    Qt Code:
    1. while(!formElements.isEmpty()) delete formElements.takeFirst();
    To copy to clipboard, switch view to plain text mode 

    works well.

    Regards,
    Bill

  7. #7
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: Dynamic objects without identifier...

    Does qDeleteAll works as well?
    It's nice to be important but it's more important to be nice.

Similar Threads

  1. Load objects from dynamic library
    By Trok in forum Qt Programming
    Replies: 10
    Last Post: 17th July 2009, 20:04
  2. Deleting objects in their event handler
    By drhex in forum Qt Programming
    Replies: 7
    Last Post: 6th May 2009, 16:08
  3. QWizard creating objects dynamically
    By afflictedd2 in forum Qt Programming
    Replies: 5
    Last Post: 24th March 2009, 15:43
  4. Lumina GLSL IDE based on QtScript and dynamic Objects
    By oc2k1 in forum Qt-based Software
    Replies: 0
    Last Post: 12th August 2008, 04:12
  5. lib("dnsapi")
    By CHeader in forum Newbie
    Replies: 10
    Last Post: 16th February 2008, 19:21

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
  •  
Qt is a trademark of The Qt Company.