Results 1 to 3 of 3

Thread: design help with QList in an interface

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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: design help with QList in an interface

    If both storeChannelItem and newsChannelItem are based on QObject, then just store a QObject in your storeChannel and newsChannel.
    Otherwise, why won't you return a list of storeChannelItems and newsChannelItems via getItems() ?

  2. #2
    Join Date
    Oct 2010
    Posts
    55
    Thanks
    1
    Thanked 11 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    9

    Default Re: design help with QList in an interface

    You could use templates:

    Qt Code:
    1. template <typename T>
    2. class ChannelInterface
    3. {
    4. public:
    5. virtual QList<T*> getItems() = 0;
    6. };
    7.  
    8. class storeChannelItem
    9. {
    10. // ...
    11. };
    12.  
    13. class newsChannelItem
    14. {
    15. // ...
    16. };
    17.  
    18. class storeChannel : public QObject, public ChannelInterface<storeChannelItem>
    19. {
    20. QList<storeChannelItem*> items;
    21. public:
    22. QList<storeChannelItem*> getItems();
    23. };
    24.  
    25. class newsChannel : public QObject, public ChannelInterface<newsChannelItem>
    26. {
    27. QList<newsChannelItem*> items;
    28. public:
    29. QList<newsChannelItem*> getItems();
    30. };
    To copy to clipboard, switch view to plain text mode 

    EDIT: Don't forget to define a virtual destructor in your interface also:

    Qt Code:
    1. template <typename T>
    2. class ChannelInterface
    3. {
    4. public:
    5. virtual ~ChannelInterface() {}
    6. virtual QList<T*> getItems() = 0;
    7. };
    To copy to clipboard, switch view to plain text mode 
    Last edited by helloworld; 7th February 2011 at 07:36.

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

    GuusDavidson (10th February 2011)

Similar Threads

  1. Cast QList<Foo*> to QList<const Foo*>
    By vfernandez in forum Qt Programming
    Replies: 0
    Last Post: 4th October 2010, 16:04
  2. Replies: 4
    Last Post: 20th August 2010, 13:54
  3. Problem with design interface
    By tux-world in forum Newbie
    Replies: 5
    Last Post: 10th March 2010, 14:19
  4. QList: Out of memory - without having defined QList
    By miroslav_karpis in forum Qt Programming
    Replies: 1
    Last Post: 27th March 2009, 08:42
  5. Replies: 3
    Last Post: 5th October 2008, 23:41

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.