Results 1 to 3 of 3

Thread: Out of bounds Qlist

  1. #1

    Unhappy Out of bounds Qlist

    Hello! a new noob is here ^^

    I`m getting the following error as I use clear() in a QListWidget from my ui:

    Qt Code:
    1. ASSERT failure in QList<T>::operator[]: "index out of range", file ../../QT/2010.05/qt/include/QtCore/../../src/corelib/tools/qlist.h, line 463
    To copy to clipboard, switch view to plain text mode 


    the QListWidget is adding itens correctly, but it crashes as I try to remove them.
    I tried using takeItem inside a for but the same error ocurred
    Please help.


    Qt Code:
    1. void MyDialog::on_remove_my_bt_clicked()
    2. {
    3. int currentIdx = ui->my_list->currentIndex().row();
    4. if(currentIdx>-1){
    5. listA.removeAt(currentIdx);
    6. if(listA.size()>0){
    7. updateMyList();
    8. }else{
    9. ui->my_list->clear();//<- error here
    10. listReady = false;
    11. }
    12. }
    13. }
    14.  
    15. void MyDialog::updateMyList()
    16. {
    17. ui->my_list->clear();//<- error here
    18. ...
    19. }
    To copy to clipboard, switch view to plain text mode 

  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: Out of bounds Qlist

    Two things:
    1. where is your assurance that the QListeWidget current index is also the index in the QList?
    2. I can't remember if QList::removeAt() changes the lists length, if it does, I don't see where your design copes with it.

    Just to test your code, and make it more defensive, put Q_ASSERT(currentIdx < listA.size()) before you call listA.removeAt(), I wont be surprised if the assert will fail.
    ==========================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.

  3. #3

    Default Re: Out of bounds Qlist

    found the problem ^^
    the clear() throwed an currentItemChanged event, and I forgot to check the index of the current item on the listener(I only checked the previus one =p) XD

    thanks for the answer, cya

Similar Threads

  1. Replies: 4
    Last Post: 20th August 2010, 13:54
  2. QDataStream << QMultiHash upper bounds?
    By ucntcme in forum Qt Programming
    Replies: 2
    Last Post: 25th June 2009, 22:40
  3. Help with out of bounds message
    By aarelovich in forum Qt Programming
    Replies: 15
    Last Post: 20th February 2009, 10:44
  4. QSvgRenderer bounds question
    By Gopala Krishna in forum Qt Programming
    Replies: 4
    Last Post: 30th November 2007, 19:33
  5. QPainter bounds question
    By Micawber in forum Qt Programming
    Replies: 3
    Last Post: 23rd October 2007, 14:09

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.