Illegal instruction (Signal SIGILL) for QSqlQuery
Hi
I have a simple SQL insertion and select statements as shown in the code below.
Code:
query.prepare("insert into contacttable (name, number) values(?,?)");
query.bindValue(":name", name);
query.bindValue(":number", number);
if(query.exec())
{
query_1.prepare("select * from contacttable");
if(query_1.exec())
{
while(query_1.next())
{
int c;
if(rec.isEmpty() != true)
c = rec.indexOf("number");
if(query_1.isValid())
name_1 = query_1.value( c).toString();
//number_1 = query_1.value(1).toString();
qDebug("name %s", name_1);
//qDebug("number %s", number_1);
}
}
return true;
}
else
return false;
Im receiving the error
Quote:
sStopped: Illegal instruction (Signal SIGILL).
at the instruction
Code:
name_1 = query_1.value( c).toString();
Unable to figure out what might be the problem.
I tried
The variable t seem to have been populated, but the error occurs in the toString line
Pls help
Thanks
Re: Illegal instruction (Signal SIGILL) for QSqlQuery
If you are true and the error come from the QVariant::toString() method maybe you should test the conversion before doing it :
QVariant::canConvert() it should give you some ideas.
Re: Illegal instruction (Signal SIGILL) for QSqlQuery
Changed the code to
Code:
query.prepare("select name, number from contacttable");
if(query.exec())
{
int c = rec.indexOf("name");
while(query.next())
{
if(query.isValid()==true)
{
if(t.canConvert<QString>() == true && t.isNull() == false)
{
qDebug("name %s", t.toString());
s = t.value<QString>();
//s=t.toString();
qDebug("name %s",s);
}
}
}
}
Neither string conversion functions work properly
Re: Illegal instruction (Signal SIGILL) for QSqlQuery
Put some debug on your code.
Something like
Code:
qDebug() << c << t;
Re: Illegal instruction (Signal SIGILL) for QSqlQuery
Check the value of 'c'. Maybe it is -1.
Re: Illegal instruction (Signal SIGILL) for QSqlQuery
The qDebug signature from the docs:
Quote:
void qDebug ( const char * msg, ... )
It is looking for a char* array, so I think you have to use one of the following:
Code:
qDebug("name %s", qPrintable(name_1));
qDebug("name %s", name_1.toAscii().data());
Or if you include <QDebug>:
Code:
qDebug() << "name" << name_1
Re: Illegal instruction (Signal SIGILL) for QSqlQuery
Thanks problem is solved.
Variable 'c' had a proper value.
qDebug("%s", name);
seemed to be the problem.
It worked with
qDebug() << name;
:)
Thanks again
Re: Illegal instruction (Signal SIGILL) for QSqlQuery
Your compiler probably warned you about it during compilation.