at() and value() are const
You can't directly change a list like this, try this:
#include <QtCore/QCoreApplication>
#include <QStringList>
#include <QDebug>
int main(int argc, char *argv[])
{
qDebug() << "Test replacing comma in a string list";
qDebug() << "";
list << "a, b, c" << "d, e, f";
for (int c = 0; c < list.count(); ++c) {
qDebug() << "Line" << c+1 << "=" << list.at(c);
}
qDebug() << "";
qDebug() << "And now without a comma:";
for (int c = 0; c < list.count(); ++c) {
line.replace(',', ' ');
list.replace(c, line);
qDebug() << "Line" << c+1 << "=" << list.at(c);
}
return a.exec();
}
#include <QtCore/QCoreApplication>
#include <QStringList>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
qDebug() << "Test replacing comma in a string list";
qDebug() << "";
QStringList list;
list << "a, b, c" << "d, e, f";
for (int c = 0; c < list.count(); ++c) {
qDebug() << "Line" << c+1 << "=" << list.at(c);
}
qDebug() << "";
qDebug() << "And now without a comma:";
for (int c = 0; c < list.count(); ++c) {
QString line = list.at(c);
line.replace(',', ' ');
list.replace(c, line);
qDebug() << "Line" << c+1 << "=" << list.at(c);
}
return a.exec();
}
To copy to clipboard, switch view to plain text mode
It gives this output:
Test replacing comma in a string list
Line 1 = "a, b, c"
Line 2 = "d, e, f"
And now without a comma:
Line 1 = "a b c"
Line 2 = "d e f"
Test replacing comma in a string list
Line 1 = "a, b, c"
Line 2 = "d, e, f"
And now without a comma:
Line 1 = "a b c"
Line 2 = "d e f"
To copy to clipboard, switch view to plain text mode
Bookmarks