Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
here is the section of code which facing this problem..

QString line = in.readLine();
        QStringList fields = line.split(",");
        fields.replaceInStrings(" ", "");
        QString IDstr = fields[0];         
        int slotDec = fields[1].toInt(&ok, 16);
        int IDstrdec = IDstr.toInt(&ok, 16);   
        int BaseID = MainWindow::NodeBaseID(IDstrdec);
        int NodeID= IDstrdec-BaseID;


would be nice if someone guide me how to come out of this problem??
Posted

normally means that exception that the list hasnt that size. Check it before any access.

Is your input correct for your splitting?

Plz learn to use a debugger.
 
Share this answer
 
You are assuming fields[1] exists, that is the QStringList contains at least two items. Such an assumption, according to the documentation[^], is wrong.
 
Share this answer
 
Comments
XamBEE 25-Nov-15 5:30am    
I am reading the file which has 4 columns. i am trying to split them with , and use them further....
what would be the better way to improve this type of situation?
As per error message "Index out of range", if you are trying to access the outside the range of the index then you will get this type of error, in your code you are calling fields[1] if there is no field with that particular index then you will get this type of error.

To resolve this type of error, before access that index check the index length.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900