Results 1 to 7 of 7

Thread: [SOLVED] qSort() and iterator const-ness(?)

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2006
    Posts
    81
    Thanks
    6
    Thanked 5 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Question [SOLVED] qSort() and iterator const-ness(?)

    Hi all,

    to give you an idea of what I am trying to do:
    My application loads a bunch of perspective plugins. Each perspective provides an action to activate itself. All actions are added to a QActionGroup that resides inside PerspectiveManager. Before the actions are presented in a toolbar, they need to be sorted.

    I am not able to sort the list of actions as provided by QActionGroup::actions(). So far, I tend to relate my problem to the iterator's const-ness, but I may be mistaken. Please have a look:
    Qt Code:
    1. QToolBar *PerspectiveManager::toolBar()
    2. {
    3. //version 1 -- This doesn't sort:
    4. //QAlgorithmsPrivate::qSortHelper(..) returns immediately
    5. //due to RandomAccessIterator end < RandomAccessIterator start
    6. qSort(actionGroup_.actions().begin(),
    7. actionGroup_.actions().end(),
    8. sortOrder);
    9.  
    10. //version 2 -- "Force non-const iterator" (?)
    11. //This enters sortOrder(..), but QAction *one and two
    12. //are not accessible there
    13. QList<QAction*>::iterator it1 = actionGroup_.actions().begin();
    14. QList<QAction*>::iterator it2 = actionGroup_.actions().end();
    15. qSort(it1,
    16. it2,
    17. sortOrder);
    18.  
    19. toolBar_.clear();
    20. toolBar_.addActions(actionGroup_.actions());
    21. return &toolBar_;
    22. }
    23.  
    24. //Not called when trying to sort as in version 1
    25. bool PerspectiveManager::sortOrder(QAction *one, QAction *two)
    26. {
    27. //demonstrate that one and two are not accessible in version 2
    28. //(running into SIGSEGV)
    29. QString s1(one->text());
    30. QString s2(two->text());
    31.  
    32. //sorting shall be done via meta object system
    33. bool b = //one is somehow "less than" two
    34.  
    35. return b;
    36. }
    To copy to clipboard, switch view to plain text mode 
    Bad thing is, I had it running in mock code, but am not getting there again...

    Thanks for you consideration!
    Last edited by zaphod.b; 28th July 2010 at 18:26. Reason: spelling corrections

Similar Threads

  1. QSort
    By skumar7777 in forum Qt Programming
    Replies: 4
    Last Post: 2nd December 2008, 06:18
  2. qSort with lessThan
    By soul_rebel in forum Qt Programming
    Replies: 4
    Last Post: 19th August 2008, 18:14
  3. const member and const method
    By mickey in forum General Programming
    Replies: 8
    Last Post: 9th April 2008, 09:44
  4. qSort() problem
    By darksaga in forum Qt Programming
    Replies: 5
    Last Post: 17th August 2007, 11:47
  5. [Qt4] QSORT
    By jane in forum Qt Programming
    Replies: 6
    Last Post: 24th May 2006, 23:38

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.