There is a segmentation fault in this function
Mar 13, 2017 at 12:24pm UTC
I need help finding the cause of segmentation fault.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
void MainWindow::tagfound(QNearFieldTarget *target)
{
QByteArray id;
id=target->uid();
qDebug()<<id<<list.size();
box->close();
if (caseflag==1)
{
for (unsigned int i =0;i<=list.size();i++)
{
if (list[i].uniqueid==id)
{
handlefoundtag(i);
qDebug()<< list[i].seatletter<<list[i].seatnumber<<list[i].uniqueid;
return ;
}
}
box->setText("Ticket not listed" );
box->exec();
return ;
}
if (caseflag==2)
{
seasonticket temp;
temp.seatletter = letter[0].toLatin1();
temp.seatnumber = ui->spinBox->value();
temp.uniqueid = target->uid();
list.push_back(temp);
qDebug()<<temp.seatletter<<temp.seatnumber<<temp.uniqueid;
box->close();
box->setText("Success!" );
box->exec();
caseflag=1;
}
}
it happens after it finishes the for loop in caseflag 1.
debug mode is not helping either it faults the moment it enters the loop.
it works just fine though if it manages to go inside the if statement in caseflag1
thanks!
Last edited on Mar 13, 2017 at 12:27pm UTC
Mar 13, 2017 at 1:07pm UTC
line 12 for (unsigned int i =0;i<=list.size();i++)
The middle condition might be causing a memory error. If the numbering starts at 0 and size is n, I'd expect the last element number would be n-1, not n.
i<list.size()
Topic archived. No new replies allowed.