Results 1 to 3 of 3

Thread: Adding signals to qt containers

  1. #1
    Join Date
    May 2009
    Posts
    133
    Thanks
    10
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Adding signals to qt containers

    Hi!

    I'd like to add signals to qt container informing about changes in a container.
    For example signal itemAdded should be emitted when new element is added and signal itemRemoved should be emitted when an element is removed from the container.

    What's the right way of doing this?

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Adding signals to qt containers

    I don't have any idea for that, but i can tell you what you shouldn't do: don't derivate from the container class, Qt's containers, just like STL's ones, are not made to become base-classes (they deliberately don't have virtual destructor)

    Maybe you can use the container as member in your class, but you will need to "redirect" the functionality so that your MyVector class to have the functionality of QVector and adding/removing items to emit signals (so this might not be an acceptable solution), so wait for other ideas and don't derivate classes from container classes.

  3. The following user says thank you to Zlatomir for this useful post:

    zoz (4th June 2010)

  4. #3
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Adding signals to qt containers

    Like Zlatomir says, the container classes are usually used in a "management" class.

    Take for example the ItemContainer class

    Qt Code:
    1. class ItemContainer : public QObject
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. ItemContainer();
    7.  
    8. void addItem(Item); // can be slots too
    9. void removeItem(Item);
    10.  
    11. signals:
    12. void itemAdded();
    13. void itemRemoved();
    14.  
    15. private:
    16. QVector<Item> itemList;
    17. };
    To copy to clipboard, switch view to plain text mode 

    What do you want to do?

  5. The following user says thank you to tbscope for this useful post:

    Zlatomir (3rd June 2010)

Similar Threads

  1. Replies: 1
    Last Post: 25th June 2010, 13:17
  2. Qt containers or STL containers?
    By sparticus_37 in forum Newbie
    Replies: 2
    Last Post: 11th May 2010, 15:12
  3. Dynamic widgets adding and connecting signals& slots
    By jjbabu in forum Qt Programming
    Replies: 2
    Last Post: 22nd May 2009, 12:36
  4. QVector, containers, deep copy
    By TheKedge in forum Qt Programming
    Replies: 2
    Last Post: 23rd January 2007, 05:45
  5. scrolled widgets containers in Mainwindow
    By antonio.r.tome in forum Qt Programming
    Replies: 1
    Last Post: 24th October 2006, 14:40

Tags for this Thread

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.