Results 1 to 4 of 4

Thread: subclasing a Qlist?

  1. #1
    Join Date
    Jan 2008
    Posts
    39
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default subclasing a Qlist?

    i have problems when i try to use the iterator with a list an a custom class T. it seems that is out of scope.
    this is an example that explains better my point.
    Qt Code:
    1. include "t.h"
    2. include <QList>
    3. class p
    4. {
    5. public:
    6. void my_function();
    7. private:
    8. QList<T> list;
    9. }
    To copy to clipboard, switch view to plain text mode 
    in the implementation:
    Qt Code:
    1. T::my_funcion()
    2. {
    3. QList<T>::iterator it;//here it seems to be the problem,, because i think this class P, isnt the main class
    4. for(it=list.begin();it!=list.end();it++)
    5. {
    6. //at this time i an only avaible to do this
    7. list.at(i).show();//where show() is an public function of the object T
    8. }
    9. //obviouslly the compiler show the message warning that is not right to do this
    10. //thenn compiler doesnt do nothinhg and do not compile the program
    11. }
    To copy to clipboard, switch view to plain text mode 
    the main intention is to declare a object that use the QList class an declare function to work whit this class in the main class
    some help pleasa!!
    Last edited by wysota; 21st March 2010 at 08:58.

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: subclasing a Qlist?

    Is your T derived from QWIdget ?
    If yes, you are doing it wrong. From the code, you are storing list as QList<T>. This requires copy constructor of T.
    But QWidget doesnt provide that.
    So your implementation should be like QList<T*>, and then call list.at(i)->show();

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: subclasing a Qlist?

    Why are you mixing iterators and index basex access. The scope you posted is nonsens. Try to skip the iterator based aproach and try to use only the indexed based one:
    Qt Code:
    1. for (int i = 0; i < list.size(); ++i) {/*...*/}
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2008
    Posts
    39
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: subclasing a Qlist?

    gracias, its was derived from Qwidget

Similar Threads

  1. Copying an QList into a new, sorted QList.
    By Thomas Wrobel in forum Newbie
    Replies: 3
    Last Post: 11th January 2010, 18:27
  2. QList inside a QList
    By jano_alex_es in forum Newbie
    Replies: 2
    Last Post: 1st July 2009, 11:59
  3. QList: Out of memory - without having defined QList
    By miroslav_karpis in forum Qt Programming
    Replies: 1
    Last Post: 27th March 2009, 08:42
  4. QList<QList > question
    By SubV in forum Qt Programming
    Replies: 3
    Last Post: 25th July 2008, 15:14
  5. QList
    By sabeesh in forum Qt Programming
    Replies: 4
    Last Post: 21st September 2007, 19:32

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.