PDA

View Full Version : Illegal instruction (Signal SIGILL) for QSqlQuery



yannifan
19th August 2011, 11:38
Hi

I have a simple SQL insertion and select statements as shown in the code below.


QString name_1, number_1;
QSqlQuery query(iLbsDb);
query.prepare("insert into contacttable (name, number) values(?,?)");
query.bindValue(":name", name);
query.bindValue(":number", number);

if(query.exec())
{
QSqlQuery query_1(iLbsDb);
query_1.prepare("select * from contacttable");

if(query_1.exec())
{
while(query_1.next())
{
QSqlRecord rec = query_1.record();
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


sStopped: Illegal instruction (Signal SIGILL).

at the instruction


name_1 = query_1.value( c).toString();

Unable to figure out what might be the problem.

I tried


QVariant t = query_1.value(c);
QString s = t.toString();


The variable t seem to have been populated, but the error occurs in the toString line

Pls help

Thanks

nix
19th August 2011, 12:25
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.

yannifan
19th August 2011, 13:52
Changed the code to




QSqlQuery query;
query.prepare("select name, number from contacttable");
if(query.exec())
{
QSqlRecord rec = query.record();
int c = rec.indexOf("name");
while(query.next())
{
if(query.isValid()==true)

{
QString s;
QVariant t = query.value(c);
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

nix
19th August 2011, 14:12
Put some debug on your code.
Something like


QVariant t = query.value(c);
qDebug() << c << t;

wysota
19th August 2011, 14:28
Check the value of 'c'. Maybe it is -1.

norobro
19th August 2011, 22:03
The qDebug signature from the docs:
void qDebug ( const char * msg, ... )It is looking for a char* array, so I think you have to use one of the following:
qDebug("name %s", qPrintable(name_1));
qDebug("name %s", name_1.toAscii().data());Or if you include <QDebug>:
qDebug() << "name" << name_1

yannifan
20th August 2011, 18:50
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

wysota
20th August 2011, 19:21
Your compiler probably warned you about it during compilation.