PDA

View Full Version : const QStringList discards qualifiers



kandalf
25th January 2009, 00:28
Hello guys after googling a while and reading about references, I still can't get what's wrong with this. I'm getting two compiler error and both say:

error: passing ‘const QStringList’ as ‘this’ argument of ‘QStringList& QStringList::operator<<(const QString&)’ discards qualifiers
The code generating this error is:

QString DBMigrator::parsePostGISSrcFields(const TableInfo *tableInfo, const bool &ignore) const
{
GeometryColumnInfo *column;
QStringList fields;
QString field;

foreach(field, tableInfo->fieldNames())
{
foreach(column, geometryColumns[tableInfo->name()])
{
if (field == column->columnName())
{
if (!ignore)
{
this->ignoredFields << field;
}
else
{
fields << QString("AsText(%1)").arg(field);
this->geometryFields << field;
}
}
else
{
fields << field;
}
}
}
// qDebug(QString("%1:\n %2").arg(tableInfo->name()).arg(fields.join(", ")).toAscii());

return fields.join(", ");
}
And the lines are where appending QStrings to the QStringLists (this->geometryFields, this->ignoredFields) both QStringLists are private to the class.

I don't know what's wrong, what confuses me more, is that if I declare a QStringList local to this method and do the append operations on that QStringList, I got no error.

Can anybody explain me what's happening, what am I doing wrong? or point me to a document that explains something like this?

Thanx a lot in advance.

Cheers.

aamer4yu
25th January 2009, 07:04
How are your this->ignoredFields and this->geometryFields declared ??
I see that your function is const member function.

So if you are modifying ur member variables in this function, they should be mutable .
Are your this->ignoredFields and this->geometryFields mutable ? if not , declare mutable and try.

kandalf
25th January 2009, 19:09
Thanx a lot. I had a misconception of const functions.
Just for information purposes, I did declared mutable and it worked, but I redeclare my function to not to be const, since it had no point to be const.

Thanx a lot again.

Cheers.