PDA

View Full Version : index out of range



akkarachai
6th January 2020, 08:43
I try to send UDP massage but I got this massage

13310

How can I fix this
here is my UDP sender code

QString datagrama = ui->lw_catalogList->currentItem()->text();
qDebug() << datagrama;
//mSocket->writeDatagram()
ui->lw_entityList->currentItem();
QStringList allNamesAsAList;
int names = ui->lw_entityList->count();
for(int i = 0; i < names; i++)
{
allNamesAsAList << ui->lw_entityList->item(i)->text().toLatin1();
}
qDebug() << allNamesAsAList;
for(int j = 0; j <= allNamesAsAList.size(); j++){
QByteArray entity;
entity.append(allNamesAsAList.at(j));
mSocket->writeDatagram(entity, QHostAddress::LocalHost,12345);
}

ChrisW67
6th January 2020, 10:08
Fix line 12.

akkarachai
7th January 2020, 01:51
What did I do wrong?

d_stranz
7th January 2020, 03:37
What did I do wrong?

If you are indexing into an array, and the first index is zero, what should the last index value be?