mikro
25th September 2006, 22:47
sorry for posting what i am afraid is a pure c++-problem here, but at least it is about a qt-program:
i have a loop going through a query and a QMap where i want to store the type and name of each column that is found. so i am trying to put the result of QSqlField::type() into my QMap, but this gives an error because it is const. Why is that? after all i had expected i am actually only copying the value into my QMap so no need to care about the original being const?
the code looks like this:
while (query.next()) {
QSqlRecord rec = query.record();
for (int col=0;col<rec.count();col++) {
QSqlField field = rec.field(col);
if (row == 0) {
QMap<QString,QVariant>* currCol = &columns.value(col);
currCol->insert("type",field.type()); // first error
currCol->insert("name",field.name()); // second error
}
qDebug() << "working on row " << row << ", column " << col;
}
tableData.value(row) = rec; //third error
row++;
}
and in the .h i have:
QMap<int,QSqlRecord> tableData;
QMap<int,QMap<QString,QVariant> > columns;
the errors i am getting are all like this:
passing `const QString' as `this' argument of `QString& QString::operator=(char)' discards qualifiers
i have a loop going through a query and a QMap where i want to store the type and name of each column that is found. so i am trying to put the result of QSqlField::type() into my QMap, but this gives an error because it is const. Why is that? after all i had expected i am actually only copying the value into my QMap so no need to care about the original being const?
the code looks like this:
while (query.next()) {
QSqlRecord rec = query.record();
for (int col=0;col<rec.count();col++) {
QSqlField field = rec.field(col);
if (row == 0) {
QMap<QString,QVariant>* currCol = &columns.value(col);
currCol->insert("type",field.type()); // first error
currCol->insert("name",field.name()); // second error
}
qDebug() << "working on row " << row << ", column " << col;
}
tableData.value(row) = rec; //third error
row++;
}
and in the .h i have:
QMap<int,QSqlRecord> tableData;
QMap<int,QMap<QString,QVariant> > columns;
the errors i am getting are all like this:
passing `const QString' as `this' argument of `QString& QString::operator=(char)' discards qualifiers