Results 1 to 4 of 4

Thread: Error:Assert Failure QLIst<t> index out of range

  1. #1
    Join Date
    Apr 2011
    Posts
    36
    Thanks
    3
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Error:Assert Failure QLIst<t> index out of range

    hi,

    my app has some balloons with alphabets A-Z as text. I dont want to repeat the balloon with same character,I retrieved items from scene to QList.after completion of all letters,my app has to halt.but in middle itself it is giving error of Assert failure index out of range.can anyone help in correction of error

    my code:
    Qt Code:
    1. void GraphicsScene::createBallon(void)
    2. {
    3. QList<QGraphicsItem *>itemno=items();
    4. qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
    5. int random = qrand() % 26;
    6. for(int i=1;i<itemno.size();i++)
    7. {
    8. Ballon *temp=qgraphicsitem_cast<Ballon*>(itemno.at(i));
    9. if(temp->getText()==str[random])
    10. return;
    11. }
    12. Ballon *ball = new Ballon(str[random]);
    13. ball->setPos(500 , 550);
    14. addItem(ball);
    15. if(itemno.size()>26)
    16. interval->stop();
    17. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Error:Assert Failure QLIst<t> index out of range

    What is str ? My first guess after quick glimpse at this code is that str has less elements than random value, so you are trying to access element out of range.
    Btw. this code is not safe:
    Qt Code:
    1. Ballon *temp=qgraphicsitem_cast<Ballon*>(itemno.at(i));
    2. if(temp->getText()==str[random])
    3. return;
    To copy to clipboard, switch view to plain text mode 
    What if at some point you will insert items that are not "ballons" ? temp will be NULL and calling temp->getText() will cause crash. Check it like this:
    Qt Code:
    1. Ballon *temp=qgraphicsitem_cast<Ballon*>(itemno.at(i));
    2. if(temp and temp->getText()==str[random])
    3. return;
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Error:Assert Failure QLIst<t> index out of range

    At line 6 you start your indexes at 1 rather than the more conventional 0. Is that deliberate?

  4. #4
    Join Date
    Apr 2011
    Posts
    36
    Thanks
    3
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Error:Assert Failure QLIst<t> index out of range

    hi,

    thanks to all.my problem is solved.i gave length of str is lesser than the random value.
    i want to display tis graphical ballons in circular way. how can i try this?
    i used setPos code its displaying at top of view that too half cut.how can i get it in middle of the scene?
    Qt Code:
    1. setPos(::sin((i * 6.28) /26) * 200,::cos((i * 6.28) /26) * 200);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 6
    Last Post: 8th April 2011, 21:15
  2. Problem debugging Assert failure.
    By Doug Broadwell in forum Qt Programming
    Replies: 3
    Last Post: 3rd January 2009, 18:39
  3. Debugging ASSERT failure in Qt header.
    By Doug Broadwell in forum Qt Programming
    Replies: 6
    Last Post: 27th December 2008, 01:40
  4. QList index out of range problem
    By MarkoSan in forum Qt Programming
    Replies: 2
    Last Post: 26th March 2008, 08:40
  5. QWT assert failure
    By Andimat in forum Qwt
    Replies: 1
    Last Post: 21st June 2007, 14:36

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.