Yet again, another pointer issue , these things really bother me
Could someone please explain, what's wrong with the code in the while-loop ?
What do I have to (add/remove) to get this to work ?
The first line seems to work fine, it returns the name of the field in the Database, the second one returns nada, zero, zip, squad, nothing, while it should return the contents of that field.
TIA
Could someone please explain, what's wrong with the code in the while-loop ?
What do I have to (add/remove) to get this to work ?
The first line seems to work fine, it returns the name of the field in the Database, the second one returns nada, zero, zip, squad, nothing, while it should return the contents of that field.
void mainWindow::Query()
{
QSqlQuery *query;
QSqlRecord *record;
query = new QSqlQuery ( "SELECT name, surname FROM user" );
record = new QSqlRecord();
*record = query->record();
while ( query->next() )
{
// This line works and returns the name of the field in the database.
QMessageBox::information ( this, "Field", record->fieldName ( 1 ) );
// This line doesn't and should return the contents or that field.
QMessageBox::information ( this, "Field contents", record->value ( 1 ).toString() );
}
delete record;
delete query;
record = 0, query = 0;
}
{
QSqlQuery *query;
QSqlRecord *record;
query = new QSqlQuery ( "SELECT name, surname FROM user" );
record = new QSqlRecord();
*record = query->record();
while ( query->next() )
{
// This line works and returns the name of the field in the database.
QMessageBox::information ( this, "Field", record->fieldName ( 1 ) );
// This line doesn't and should return the contents or that field.
QMessageBox::information ( this, "Field contents", record->value ( 1 ).toString() );
}
delete record;
delete query;
record = 0, query = 0;
}
Comment