Results 1 to 2 of 2

Thread: Circular QLinkedList

  1. #1
    Join Date
    Feb 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Circular QLinkedList

    How can one create a circular linked list?One witch iterator jumps from end to begin automatically .
    i.e.

    Qt Code:
    1. QLinkedList<QObject> list;
    2. QLinkedList<QObject>::iterator indexer;
    3. //...
    4. list.begin().i->p = list.end().i->n;
    5. list.begin().i->p->t = list.end().i->t;
    6. list.end().i->n->t = list.begin().i->t;
    7.  
    8. indexer= list.begin();
    9. indexer++;
    To copy to clipboard, switch view to plain text mode 

    When indexer reaches list.end I want indexer++ to jump automatically at list.begin.
    For some reason program crashes at line 5.
    Is there a better solution to this problem?

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Circular QLinkedList

    How can one create a circular linked list?One witch iterator jumps from end to begin automatically
    You will have to subclass QLinkedList, and overload the end() methods.
    Be aware, that this might have implications on other methods you will have to override (as in: what happens when you delete memebers etc).

    For some reason program crashes at line 5.
    Returns an STL-style iterator pointing to the imaginary item after the last item in the list.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. circular buttons
    By moabi in forum Newbie
    Replies: 2
    Last Post: 18th March 2010, 04:28
  2. Circular Linklist.
    By AmolShinde_8 in forum Qt Programming
    Replies: 2
    Last Post: 31st October 2008, 04:23
  3. Circular scale
    By fruzzo in forum Qwt
    Replies: 1
    Last Post: 6th March 2008, 07:20
  4. QLinkedList and iterators
    By eu.x in forum Newbie
    Replies: 1
    Last Post: 19th April 2007, 19:38
  5. Is there a circular reference here?
    By rh in forum General Programming
    Replies: 3
    Last Post: 22nd January 2006, 21:51

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.