Unsolved ASSERT failure in QList<T>::operator[]: "index out of range"
-
If I sent start command from server, output displayed like this on client side
WebSocket connected message received : "straight|xy|3|0" start xy value Received from server : "straight|xy|3|0" start x value emitted to Robot : 3 start y value emitted to Robot: 0 int of start x value emitted : 3 int start y value emitted : 0
If I click start button on client side that time only I got the error.
WebSocket connected start xy value Received from server : "" ASSERT failure in QList<T>::operator[]: "index out of range", file /usr/include/arm-linux-gnueabihf/qt5/QtCore/qlist.h, line 487
-
@Jerwinprabu You see: you're trying to split an empty string, this is not going to work. So please add some check to your code as @joeQ suggested.
And you should check why you don't get what server sent, but this is another issue. -
@joeQ When I was try to run the program I got the error
error: return-statement with a value, in function returning 'void' [-fpermissive] return false;
-
@Jerwinprabu (⊙o⊙)…
bool myFunctionName() ///< Notes; function return value type must bool { /* ... */ return true; }
-
-
@jsulm @joeQ Thanks for your help. Ya @joeQ given proper sample. I have tried that. Here I have posted the solution now client side that is working fine, one time I want to check from server side. Kindly check, if anything wrong awaiting for your further response
startvaluexy = Client::straightxy; qDebug() << "start xy value Received from server :" << startvaluexy; QStringList xy = startvaluexy.split("|"); int xySize = xy.size(); qDebug() << "start xy size :" << xySize; if(xySize > 4){ x = xy[2]; y = xy[3]; } QString num1 = x; int x = num1.toInt(); qDebug() << "start x value :" << x; QString num2 = y; int y = num2.toInt(); qDebug() << "start y value :" << y; xstart = x; ystart = y;
After checking the size will modify this xySize > 4
-
@Jerwinprabu said in ASSERT failure in QList<T>::operator[]: "index out of range":
if(xySize > 4){
shouldn't it be
if(xySize >= 4){
?
And if it is not >= 4 what would be the values of x and y? Shouldn't you just skip processing in this case (do return as @joeQ suggested)?What are you trying to do with this
QString num1 = x; int x = num1.toInt();
?! Why do you assign an integer to a string and then convert this string to integer again? Same for
QString num2 = y; int y = num2.toInt();
-
@jsulm from server I will receive the string then I want to convert that string into int. Again I want to convert for sending to server(for map).
-
@Jerwinprabu Then why do you convert it back from string to int? x is already int, what's the point to convert from string to int?
AlsoQString num1 = x;
is not a conversion to string from int! It will not even compile. If you want to convert int to string then do it like shown here http://doc.qt.io/qt-5/qstring.html#number
-
@jsulm Because I want to take that value to int only xstart, ystart. I want to convert from string to int only. x, y is not int.
QString x; QString y;
-
@Jerwinprabu Again
QString num1 = x; int x = num1.toInt();
x already contains the integer value! Now you convert it to string then again to int - it will be same as before.
int x = 1; QString num1 = QString::number(x); x = num1.toInt(); qDebug() << x;
What do you think the last line will print out?
Shouldn't it be justQString num1 = QString::number(x); xstart = x;
?
-
@Jerwinprabu Also here you redefine the variable x
QString num1 = x; int x = num1.toInt();
is there a reason why you're doing this?
-
After chatting with @Jerwinprabu I realised that I misunderstood his code: x and y are actually QString not int.
-
@jsulm
Well x is a pretty confusing name for a string in most cases.
I was sure also it was int.