Results 1 to 3 of 3

Thread: Index out of Range

  1. #1
    Join Date
    May 2008
    Posts
    42
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4

    Default Index out of Range

    Hi Friends,

    I am getting an error 'Index out of Range' in this program

    Qt Code:
    1. QDir dir(ImagesDirPath);
    2. dir.setFilter(QDir::Files | QDir::NoSymLinks);
    3. QStringList filters;
    4. filters << "*.xml";
    5. dir.setNameFilters(filters);
    6. dir.setSorting(QDir::Name);
    7.  
    8. QStringList Strlist;
    9. QFileInfoList list = dir.entryInfoList();
    10.  
    11. for (int i = 0; i < list.size(); ++i)
    12. {
    13. QFileInfo fileInfo = list.at(i);
    14. Strlist<<fileInfo.baseName();
    15. }
    16.  
    17. ui.comboBox_2->insertItems(0,Strlist);
    To copy to clipboard, switch view to plain text mode 

    How to solve this?

    Thanks in Advance..
    Last edited by jpn; 19th August 2008 at 13:10. Reason: missing [code] tags

  2. #2
    Join Date
    Apr 2008
    Posts
    104
    Thanks
    8
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Index out of Range

    try this:
    Qt Code:
    1. for (int i = 0; i < list.size() - 1; ++i)
    2. {
    3. QFileInfo fileInfo = list.at(i);
    4. Strlist<<fileInfo.baseName();
    5. }
    To copy to clipboard, switch view to plain text mode 
    //i.e. list.size() - 1

  3. #3
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Index out of Range

    try to avoid indexing when you do not need it:
    Qt Code:
    1. foreach (const QFileInfo &fi, dir.entryInfoList())
    2. l << fi.baseName();
    To copy to clipboard, switch view to plain text mode 


    PS: "< list.size()" should be correct.
    Have you tried using a debugger to find the line that causes the crash?

    HTH

Similar Threads

  1. Replies: 3
    Last Post: 25th July 2008, 15:30
  2. QList index out of range problem
    By MarkoSan in forum Qt Programming
    Replies: 2
    Last Post: 26th March 2008, 09:40
  3. QProcess readStdOut index
    By user_mail07 in forum Qt Programming
    Replies: 1
    Last Post: 27th February 2008, 20:37
  4. 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
  5. Qt and MySQL Database Connection
    By shamik in forum Qt Programming
    Replies: 41
    Last Post: 6th October 2006, 13:48

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.