Results 1 to 5 of 5

Thread: qstringlist index out of range at declaration!

  1. #1
    Join Date
    Nov 2010
    Posts
    142
    Thanks
    24
    Qt products
    Qt4
    Platforms
    Unix/X11

    Unhappy qstringlist index out of range at declaration!

    I don't know if this is possible...but I get run time error when the program reaches this line:

    Qt Code:
    1. QStringList numberOfComponentsPerSet, namesOfSets;
    To copy to clipboard, switch view to plain text mode 

    ASSERT failure in QList<T>::at: "index out of range", file c:\Qt\4.7.4\include/QtCore/../../src/corelib/tools/qlist.h, line 456

    How can I be out of range when creating the variables?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: qstringlist index out of range at declaration!

    You probably have another bug that has corrupted the stack so that by the time you reach that statement, your program has already run off the rails. Look at what is going on before you get to the crash.

  3. #3
    Join Date
    Nov 2010
    Posts
    142
    Thanks
    24
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: qstringlist index out of range at declaration!

    i use the debug mode step by step. When this line is executed I get that error.
    In mainwindow.cpp I have a button which calls a slot function
    Qt Code:
    1. connect( loadComponentParameters, SIGNAL(triggered()),this->widget,SLOT(loadComponentParameterTableFromFile()) );
    To copy to clipboard, switch view to plain text mode 
    when the program gets into the slot function, it works fine, until I get to that declaration.
    Moving the declaration in several positions in the function has the same effect. Runtime error when I get there.

    Qt Code:
    1. void MyWidget::loadComponentParameterTableFromFile()
    2. {
    3. toggleAutomaticReplotStatus(false);
    4. modelVector->clear();
    5. QString line;
    6. int lineIndex = 0,model_index = 0, row_index = 0,column_index = 0, numberOfSets = 0;
    7. QStringList numberOfComponentsPerSet, namesOfSets;
    To copy to clipboard, switch view to plain text mode 
    The program crashes when I just click the loadComponentParameters button!
    Any ideas?!

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: qstringlist index out of range at declaration!

    this->widget
    Has "widget" been instantiated at the point where this slot is connected (not invoked)? If you are passing a bogus pointer into the connect call, the slot is getting called on a bogus instance. What is the value of "this" when you step inside the slot? Does it look reasonable, and does it match the value of "widget" created by MainWindow?

  5. #5
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: qstringlist index out of range at declaration!

    Does this line
    Qt Code:
    1. modelVector->clear();
    To copy to clipboard, switch view to plain text mode 
    by any chance clear a QList that is used as the internal data structure of a QAbstractItemModel? If so, have a look at QAbstractItemModel::beginResetModel() and QAbstractItemModel::endResetModel().

Similar Threads

  1. Index out of range problem for a xml file
    By Niamita in forum Qt Programming
    Replies: 1
    Last Post: 3rd November 2011, 07:11
  2. Replies: 3
    Last Post: 27th July 2011, 09:30
  3. Replies: 6
    Last Post: 8th April 2011, 21:15
  4. Index out of Range
    By santhoshv84 in forum Qt Programming
    Replies: 2
    Last Post: 19th August 2008, 15:33
  5. QList index out of range problem
    By MarkoSan in forum Qt Programming
    Replies: 2
    Last Post: 26th March 2008, 08:40

Tags for this Thread

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.