Results 1 to 3 of 3

Thread: QList index out of range problem

  1. #1
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Talking QList index out of range problem

    Hi to all!

    I have following method with its code:
    Qt Code:
    1. qint16 CApplicationSettings::searchSettingsForIndex(const QString& strHub, const QString& strKey)
    2. {
    3. if(m_SettingsValues.size()>0)
    4. for (qint16 iIndex=0; iIndex=m_SettingsValues.size(); iIndex++)
    5. if(m_SettingsValues.at(iIndex).strHub==strHub)
    6. if(m_SettingsValues.at(iIndex).strKey==strKey)
    7. return iIndex; // returns index of found record
    8.  
    9. return RECORD_NOT_FOUND; // not found
    10. }
    To copy to clipboard, switch view to plain text mode 
    Once called, the application crashes with following error:
    Qt Code:
    1. warning: Lowest section in C:\WINDOWS\system32\xpsp2res.dll is .rsrc at 20001000
    2. warning: QLayout: Cannot add null widget to QHBoxLayout/
    3.  
    4. Current language: auto; currently c++
    5. warning: ASSERT failure in QList<T>::at: "index out of range", file ../../../../Qt/4.3.4/include/QtCore/../../src/corelib/tools/qlist.h, line 391
    To copy to clipboard, switch view to plain text mode 
    It is obvious I try to read out of range record, but I simply do not get it why? This code seems perfect to me ... The app crashes in line 5 of method, in the first comparsion.
    Qt 5.3 Opensource & Creator 3.1.2

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QList index out of range problem

    The loop is incorrect. The second argument of the for statement should probably say "iIndex<m_SettingsValues.size()". Now you are asigning an invalid index there and so the loop tries to read after the last element of the list.

  3. The following user says thank you to wysota for this useful post:

    MarkoSan (26th March 2008)

  4. #3
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QList index out of range problem

    Ohhh, my good, what a retard mistake!!!! Thanks, wysota!!!
    Qt 5.3 Opensource & Creator 3.1.2

Similar Threads

  1. Qtopia core 4.2.2 cross compile make error
    By smiyai18 in forum Installation and Deployment
    Replies: 2
    Last Post: 28th August 2007, 18:04
  2. Problem with index in a QTreeView
    By hubert_p in forum Qt Programming
    Replies: 4
    Last Post: 22nd October 2006, 16:54
  3. Qt and MySQL Database Connection
    By shamik in forum Qt Programming
    Replies: 41
    Last Post: 6th October 2006, 13:48
  4. QList problem
    By acix in forum General Programming
    Replies: 6
    Last Post: 29th April 2006, 14:08

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.