gpt4 book ai didi

c++ - QList ::operator []中的ASSERT失败: “index out of range”文件/usr/include/arm-linux-gnueabihf/qt5/QtCore/qlist.h

转载 作者:行者123 更新时间:2023-12-02 10:08:42 24 4
gpt4 key购买 nike

我最近一直在从事一个项目。当我尝试运行项目时,出现此错误:

/ASSERT failure in QList<T>::operator[]: "index out of range", file /usr/include/arm-linux-gnueabihf/qt5/QtCore/qlist.h, line 487
The program has unexpectedly finished.

我应该如何追踪问题的根源?

我相信添加此代码会导致错误
startvaluexy = Client::straightxy;
qDebug() << "start value Received from server :" << startvaluexy;
QStringList xy = startvaluexy.split("|");

x = xy[2];

QString num1 = x;
int x = num1.toInt();

qDebug() << "start x value :" << x;

y = xy[3];

QString num2 = y;
int y = num2.toInt();

qDebug() << "start y value :" << y;

当此 x = xy[2]; y = xy[3];取出后,可以正常运行。

最佳答案

您必须使用xy.size()检查通过split返回的xy列表的大小

...不确定您的代码是什么意思,但是我会写这样的东西

if(xySize >= 4){
QString num1 = xy[2];
QString num2 = xy[3];

int x = num1.toInt();
int y = num2.toInt();

qDebug() << "start x value :" << x;
qDebug() << "start y value :" << y;

xstart = x;
ystart = y;
}

关于c++ - QList <T>::operator []中的ASSERT失败: “index out of range”文件/usr/include/arm-linux-gnueabihf/qt5/QtCore/qlist.h,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43842049/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com