PDA

View Full Version : SQLite truble



tranfuga25s
16th August 2006, 02:56
I've got problems with this code:


QSqlQuery *cola = new QSqlQuery("SELECT id, pregunta, respuesta, referencia, dificultad, tema FROM preguntas");
if( cola->exec() )
{
while( cola->next() )
{
cout<<"-----------------------------------------------"<<endl;
cout<<"Numero de pregunta: "<<cola->value(0).toInt()<<endl;
cout<<"Tema:" <<cola->value(5).toInt()<<endl;
cout<<"Dificultad:" <<cola->value(4).toInt()<<endl;
cout<<"Texto: " <<cola->value(1).toString()<<endl;
cout<<"Respuesta:" <<cola->value(2).toString()<<endl;
cout<<"Referencia:" <<cola->value(3).toString()<<endl;
}
delete(cola);
return;
}

When run it, it's stops al the first .toString() output. If the last 3 outputs are not there the cycle work fine... Any Idea????...
Using Qt 3 with linux
Thanks

jacek
16th August 2006, 03:00
Try:
cout << "Texto: " << cola->value(1).toString().ascii() << endl;

BTW. Why do you create QSqlQuery with new, if you delete it immediately? Won't it be simplier if you would create it on the stack?

tranfuga25s
16th August 2006, 03:05
the ascii() function didnt work...

the pointer thats it's created and deleted it's because sqlite block the whole db in each query. I've already tryed with QSqlCursor but does't work too. Any another idea?
what do you mean with create it on stack? using only one query in the wole object?

gfunk
16th August 2006, 20:04
I find a lot of java programmers use new instead of the stack. Force of habit :p

croland
16th August 2006, 21:13
Try:
cout << "Texto: " << cola->value(1).toString().toAscii().data() << endl;

aMan
21st August 2006, 15:10
what do you mean with create it on stack? using only one query in the wole object?
no..
just write

QSqlQuery cola("SELECT id, pregunta, respuesta, referencia, dificultad, tema FROM preguntas");
and dots " . " instead of the arrows "->" when requesting a member of cola..

then you don't need the "delete cola"..

regards..
aman..