Examples/Doc snippets: Fix single-character string literals.

Use character literals where applicable.

Change-Id: I79fa5018f05735201ae35ee94ba0d356fcad1056
Reviewed-by: Topi Reiniö <topi.reinio@digia.com>
This commit is contained in:
Friedemann Kleint 2015-10-13 09:06:58 +02:00
parent dab4877a0a
commit f9bf737d74
34 changed files with 87 additions and 87 deletions

View File

@ -112,7 +112,7 @@ protected:
QString str = QString::number(n); QString str = QString::number(n);
if (str.length() == 1) if (str.length() == 1)
str.prepend("0"); str.prepend('0');
QFont font; QFont font;
font.setFamily("Helvetica"); font.setFamily("Helvetica");

View File

@ -219,8 +219,8 @@ bool FileManager::generateFiles()
QString prefix; QString prefix;
if (!destinationPath.isEmpty()) { if (!destinationPath.isEmpty()) {
prefix = destinationPath; prefix = destinationPath;
if (!prefix.endsWith("/")) if (!prefix.endsWith('/'))
prefix += "/"; prefix += '/';
QDir dir; QDir dir;
if (!dir.mkpath(prefix)) { if (!dir.mkpath(prefix)) {
errString = tr("Failed to create directory %1").arg(prefix); errString = tr("Failed to create directory %1").arg(prefix);
@ -261,13 +261,13 @@ bool FileManager::generateFiles()
if (!destinationPath.isEmpty()) { if (!destinationPath.isEmpty()) {
prefix = destinationPath; prefix = destinationPath;
if (!prefix.endsWith("/")) if (!prefix.endsWith('/'))
prefix += "/"; prefix += '/';
} }
if (!metaInfo.name().isEmpty()) { if (!metaInfo.name().isEmpty()) {
prefix += metaInfo.name(); prefix += metaInfo.name();
if (!prefix.endsWith("/")) if (!prefix.endsWith('/'))
prefix += "/"; prefix += '/';
} }
if (!dir.mkpath(prefix)) { if (!dir.mkpath(prefix)) {
errString = tr("Failed to create directory %1").arg(prefix); errString = tr("Failed to create directory %1").arg(prefix);

View File

@ -96,7 +96,7 @@ bool MetaInfo::parse(const QByteArray &data)
QByteArray path; QByteArray path;
foreach (QVariant p, pathElements) { foreach (QVariant p, pathElements) {
if (!path.isEmpty()) if (!path.isEmpty())
path += "/"; path += '/';
path += p.toByteArray(); path += p.toByteArray();
} }

View File

@ -299,7 +299,7 @@ void Widget::printFormat(const QSurfaceFormat &format)
QString opts; QString opts;
for (size_t i = 0; i < sizeof(options) / sizeof(Option); ++i) for (size_t i = 0; i < sizeof(options) / sizeof(Option); ++i)
if (format.testOption(options[i].option)) if (format.testOption(options[i].option))
opts += QString::fromLatin1(options[i].str) + QStringLiteral(" "); opts += QString::fromLatin1(options[i].str) + QLatin1Char(' ');
m_output->append(tr("Options: %1").arg(opts)); m_output->append(tr("Options: %1").arg(opts));
for (size_t i = 0; i < sizeof(renderables) / sizeof(Renderable); ++i) for (size_t i = 0; i < sizeof(renderables) / sizeof(Renderable); ++i)

View File

@ -61,10 +61,10 @@ QStringList findFiles(const QString &startDir, QStringList filters)
QDir dir(startDir); QDir dir(startDir);
foreach (QString file, dir.entryList(filters, QDir::Files)) foreach (QString file, dir.entryList(filters, QDir::Files))
names += startDir + "/" + file; names += startDir + '/' + file;
foreach (QString subdir, dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot)) foreach (QString subdir, dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot))
names += findFiles(startDir + "/" + subdir, filters); names += findFiles(startDir + '/' + subdir, filters);
return names; return names;
} }
@ -81,7 +81,7 @@ WordCount singleThreadedWordCount(QStringList files)
f.open(QIODevice::ReadOnly); f.open(QIODevice::ReadOnly);
QTextStream textStream(&f); QTextStream textStream(&f);
while (textStream.atEnd() == false) while (textStream.atEnd() == false)
foreach(QString word, textStream.readLine().split(" ")) foreach (const QString &word, textStream.readLine().split(' '))
wordCount[word] += 1; wordCount[word] += 1;
} }
@ -100,7 +100,7 @@ WordCount countWords(const QString &file)
WordCount wordCount; WordCount wordCount;
while (textStream.atEnd() == false) while (textStream.atEnd() == false)
foreach (QString word, textStream.readLine().split(" ")) foreach (const QString &word, textStream.readLine().split(' '))
wordCount[word] += 1; wordCount[word] += 1;
return wordCount; return wordCount;

View File

@ -153,7 +153,7 @@ void Dialog::addTracks(int albumId, QStringList tracks)
for (int i = 0; i < tracks.count(); i++) { for (int i = 0; i < tracks.count(); i++) {
QString trackNumber = QString::number(i); QString trackNumber = QString::number(i);
if (i < 10) if (i < 10)
trackNumber.prepend("0"); trackNumber.prepend('0');
QDomText textNode = albumDetails.createTextNode(tracks.at(i)); QDomText textNode = albumDetails.createTextNode(tracks.at(i));

View File

@ -53,7 +53,7 @@ QVariant CustomSqlModel::data(const QModelIndex &index, int role) const
QVariant value = QSqlQueryModel::data(index, role); QVariant value = QSqlQueryModel::data(index, role);
if (value.isValid() && role == Qt::DisplayRole) { if (value.isValid() && role == Qt::DisplayRole) {
if (index.column() == 0) if (index.column() == 0)
return value.toString().prepend("#"); return value.toString().prepend('#');
else if (index.column() == 2) else if (index.column() == 2)
return value.toString().toUpper(); return value.toString().toUpper();
} }

View File

@ -79,31 +79,31 @@ void ClassWizard::accept()
if (field("comment").toBool()) { if (field("comment").toBool()) {
block += "/*\n"; block += "/*\n";
block += " " + header.toLatin1() + "\n"; block += " " + header.toLatin1() + '\n';
block += "*/\n"; block += "*/\n";
block += "\n"; block += '\n';
} }
if (field("protect").toBool()) { if (field("protect").toBool()) {
block += "#ifndef " + macroName + "\n"; block += "#ifndef " + macroName + '\n';
block += "#define " + macroName + "\n"; block += "#define " + macroName + '\n';
block += "\n"; block += '\n';
} }
if (field("includeBase").toBool()) { if (field("includeBase").toBool()) {
block += "#include " + baseInclude + "\n"; block += "#include " + baseInclude + '\n';
block += "\n"; block += '\n';
} }
block += "class " + className; block += "class " + className;
if (!baseClass.isEmpty()) if (!baseClass.isEmpty())
block += " : public " + baseClass; block += " : public " + baseClass;
block += "\n"; block += '\n';
block += "{\n"; block += "{\n";
/* qmake ignore Q_OBJECT */ /* qmake ignore Q_OBJECT */
if (field("qobjectMacro").toBool()) { if (field("qobjectMacro").toBool()) {
block += " Q_OBJECT\n"; block += " Q_OBJECT\n";
block += "\n"; block += '\n';
} }
block += "public:\n"; block += "public:\n";
@ -115,7 +115,7 @@ void ClassWizard::accept()
block += " " + className + "();\n"; block += " " + className + "();\n";
if (field("copyCtor").toBool()) { if (field("copyCtor").toBool()) {
block += " " + className + "(const " + className + " &other);\n"; block += " " + className + "(const " + className + " &other);\n";
block += "\n"; block += '\n';
block += " " + className + " &operator=" + "(const " + className block += " " + className + " &operator=" + "(const " + className
+ " &other);\n"; + " &other);\n";
} }
@ -123,11 +123,11 @@ void ClassWizard::accept()
block += "};\n"; block += "};\n";
if (field("protect").toBool()) { if (field("protect").toBool()) {
block += "\n"; block += '\n';
block += "#endif\n"; block += "#endif\n";
} }
QFile headerFile(outputDir + "/" + header); QFile headerFile(outputDir + '/' + header);
if (!headerFile.open(QFile::WriteOnly | QFile::Text)) { if (!headerFile.open(QFile::WriteOnly | QFile::Text)) {
QMessageBox::warning(0, QObject::tr("Simple Wizard"), QMessageBox::warning(0, QObject::tr("Simple Wizard"),
QObject::tr("Cannot write file %1:\n%2") QObject::tr("Cannot write file %1:\n%2")
@ -141,12 +141,12 @@ void ClassWizard::accept()
if (field("comment").toBool()) { if (field("comment").toBool()) {
block += "/*\n"; block += "/*\n";
block += " " + implementation.toLatin1() + "\n"; block += " " + implementation.toLatin1() + '\n';
block += "*/\n"; block += "*/\n";
block += "\n"; block += '\n';
} }
block += "#include \"" + header.toLatin1() + "\"\n"; block += "#include \"" + header.toLatin1() + "\"\n";
block += "\n"; block += '\n';
if (field("qobjectCtor").toBool()) { if (field("qobjectCtor").toBool()) {
block += className + "::" + className + "(QObject *parent)\n"; block += className + "::" + className + "(QObject *parent)\n";
@ -171,7 +171,7 @@ void ClassWizard::accept()
block += "{\n"; block += "{\n";
block += " *this = other;\n"; block += " *this = other;\n";
block += "}\n"; block += "}\n";
block += "\n"; block += '\n';
block += className + " &" + className + "::operator=(const " block += className + " &" + className + "::operator=(const "
+ className + " &other)\n"; + className + " &other)\n";
block += "{\n"; block += "{\n";
@ -183,7 +183,7 @@ void ClassWizard::accept()
} }
} }
QFile implementationFile(outputDir + "/" + implementation); QFile implementationFile(outputDir + '/' + implementation);
if (!implementationFile.open(QFile::WriteOnly | QFile::Text)) { if (!implementationFile.open(QFile::WriteOnly | QFile::Text)) {
QMessageBox::warning(0, QObject::tr("Simple Wizard"), QMessageBox::warning(0, QObject::tr("Simple Wizard"),
QObject::tr("Cannot write file %1:\n%2") QObject::tr("Cannot write file %1:\n%2")
@ -356,9 +356,9 @@ void CodeStylePage::initializePage()
if (baseClass.isEmpty()) { if (baseClass.isEmpty()) {
baseIncludeLineEdit->clear(); baseIncludeLineEdit->clear();
} else if (QRegExp("Q[A-Z].*").exactMatch(baseClass)) { } else if (QRegExp("Q[A-Z].*").exactMatch(baseClass)) {
baseIncludeLineEdit->setText("<" + baseClass + ">"); baseIncludeLineEdit->setText('<' + baseClass + '>');
} else { } else {
baseIncludeLineEdit->setText("\"" + baseClass.toLower() + ".h\""); baseIncludeLineEdit->setText('"' + baseClass.toLower() + ".h\"");
} }
} }
//! [16] //! [16]

View File

@ -229,7 +229,7 @@ void ImageWidget::goNextImage()
prevImage = currentImage; prevImage = currentImage;
currentImage = nextImage; currentImage = nextImage;
if (position+1 < files.size()) if (position+1 < files.size())
nextImage = loadImage(path+QLatin1String("/")+files.at(position+1)); nextImage = loadImage(path + QLatin1Char('/') + files.at(position+1));
else else
nextImage = QImage(); nextImage = QImage();
} }
@ -246,7 +246,7 @@ void ImageWidget::goPrevImage()
nextImage = currentImage; nextImage = currentImage;
currentImage = prevImage; currentImage = prevImage;
if (position > 0) if (position > 0)
prevImage = loadImage(path+QLatin1String("/")+files.at(position-1)); prevImage = loadImage(path + QLatin1Char('/') + files.at(position-1));
else else
prevImage = QImage(); prevImage = QImage();
} }
@ -276,12 +276,12 @@ void ImageWidget::goToImage(int index)
position = index; position = index;
if (index > 0) if (index > 0)
prevImage = loadImage(path+QLatin1String("/")+files.at(position-1)); prevImage = loadImage(path + QLatin1Char('/') + files.at(position-1));
else else
prevImage = QImage(); prevImage = QImage();
currentImage = loadImage(path+QLatin1String("/")+files.at(position)); currentImage = loadImage(path + QLatin1Char('/') + files.at(position));
if (position+1 < files.size()) if (position+1 < files.size())
nextImage = loadImage(path+QLatin1String("/")+files.at(position+1)); nextImage = loadImage(path + QLatin1Char('/') + files.at(position+1));
else else
nextImage = QImage(); nextImage = QImage();
update(); update();

View File

@ -319,9 +319,9 @@ RenderOptionsDialog::RenderOptionsDialog()
while (++it != tokens.end()) { while (++it != tokens.end()) {
m_parameterNames << name; m_parameterNames << name;
if (!singleElement) { if (!singleElement) {
m_parameterNames.back() += "["; m_parameterNames.back() += '[';
m_parameterNames.back() += counter + counterPos; m_parameterNames.back() += counter + counterPos;
m_parameterNames.back() += "]"; m_parameterNames.back() += ']';
int j = 8; // position of last digit int j = 8; // position of last digit
++counter[j]; ++counter[j];
while (j > 0 && counter[j] > '9') { while (j > 0 && counter[j] > '9') {

View File

@ -124,7 +124,7 @@ void MainWindow::loadFile(const QString &fileName)
if (!line.isEmpty()) { if (!line.isEmpty()) {
model->insertRows(row, 1, QModelIndex()); model->insertRows(row, 1, QModelIndex());
QStringList pieces = line.split(",", QString::SkipEmptyParts); QStringList pieces = line.split(',', QString::SkipEmptyParts);
model->setData(model->index(row, 0, QModelIndex()), model->setData(model->index(row, 0, QModelIndex()),
pieces.value(0)); pieces.value(0));
model->setData(model->index(row, 1, QModelIndex()), model->setData(model->index(row, 1, QModelIndex()),

View File

@ -246,7 +246,7 @@ void TreeModel::setupModelData(const QStringList &lines, TreeItem *parent)
while (number < lines.count()) { while (number < lines.count()) {
int position = 0; int position = 0;
while (position < lines[number].length()) { while (position < lines[number].length()) {
if (lines[number].mid(position, 1) != " ") if (lines[number].at(position) != ' ')
break; break;
++position; ++position;
} }

View File

@ -54,15 +54,15 @@ int main(int argc, char* argv[])
QFile file(":/grades.txt"); QFile file(":/grades.txt");
if (file.open(QFile::ReadOnly)) { if (file.open(QFile::ReadOnly)) {
QString line = file.readLine(200); QString line = file.readLine(200);
QStringList list = line.simplified().split(","); QStringList list = line.simplified().split(',');
model->setHorizontalHeaderLabels(list); model->setHorizontalHeaderLabels(list);
int row = 0; int row = 0;
QStandardItem *newItem = 0; QStandardItem *newItem = 0;
while (file.canReadLine()) { while (file.canReadLine()) {
line = file.readLine(200); line = file.readLine(200);
if (!line.startsWith("#") && line.contains(",")) { if (!line.startsWith('#') && line.contains(',')) {
list= line.simplified().split(","); list = line.simplified().split(',');
for (int col = 0; col < list.length(); ++col){ for (int col = 0; col < list.length(); ++col){
newItem = new QStandardItem(list.at(col)); newItem = new QStandardItem(list.at(col));
model->setItem(row, col, newItem); model->setItem(row, col, newItem);

View File

@ -88,7 +88,7 @@ QVariant Model::data(const QModelIndex &index, int role) const
if (!index.isValid()) if (!index.isValid())
return QVariant(); return QVariant();
if (role == Qt::DisplayRole) if (role == Qt::DisplayRole)
return QVariant("Item " + QString::number(index.row()) + ":" + QString::number(index.column())); return QVariant("Item " + QString::number(index.row()) + ':' + QString::number(index.column()));
if (role == Qt::DecorationRole) { if (role == Qt::DecorationRole) {
if (index.column() == 0) if (index.column() == 0)
return iconProvider.icon(QFileIconProvider::Folder); return iconProvider.icon(QFileIconProvider::Folder);

View File

@ -88,7 +88,7 @@ QVariant DomModel::data(const QModelIndex &index, int role) const
for (int i = 0; i < attributeMap.count(); ++i) { for (int i = 0; i < attributeMap.count(); ++i) {
QDomNode attribute = attributeMap.item(i); QDomNode attribute = attributeMap.item(i);
attributes << attribute.nodeName() + "=\"" attributes << attribute.nodeName() + "=\""
+attribute.nodeValue() + "\""; +attribute.nodeValue() + '"';
} }
return attributes.join(' '); return attributes.join(' ');
case 2: case 2:

View File

@ -180,7 +180,7 @@ void TreeModel::setupModelData(const QStringList &lines, TreeItem *parent)
while (number < lines.count()) { while (number < lines.count()) {
int position = 0; int position = 0;
while (position < lines[number].length()) { while (position < lines[number].length()) {
if (lines[number].mid(position, 1) != " ") if (lines[number].at(position) != ' ')
break; break;
position++; position++;
} }

View File

@ -153,8 +153,8 @@ void RegExpDialog::refresh()
QString escaped = pattern; QString escaped = pattern;
escaped.replace("\\", "\\\\"); escaped.replace("\\", "\\\\");
escaped.replace("\"", "\\\""); escaped.replace("\"", "\\\"");
escaped.prepend("\""); escaped.prepend('"');
escaped.append("\""); escaped.append('"');
escapedPatternLineEdit->setText(escaped); escapedPatternLineEdit->setText(escaped);
QRegExp rx(pattern); QRegExp rx(pattern);

View File

@ -111,8 +111,8 @@ void RegularExpressionDialog::refresh()
QString escaped = pattern; QString escaped = pattern;
escaped.replace(QLatin1String("\\"), QLatin1String("\\\\")); escaped.replace(QLatin1String("\\"), QLatin1String("\\\\"));
escaped.replace(QLatin1String("\""), QLatin1String("\\\"")); escaped.replace(QLatin1String("\""), QLatin1String("\\\""));
escaped.prepend(QLatin1String("\"")); escaped.prepend(QLatin1Char('"'));
escaped.append(QLatin1String("\"")); escaped.append(QLatin1Char('"'));
escapedPatternLineEdit->setText(escaped); escapedPatternLineEdit->setText(escaped);
QRegularExpression rx(pattern); QRegularExpression rx(pattern);

View File

@ -60,7 +60,7 @@ VariantDelegate::VariantDelegate(QObject *parent)
dateExp.setPattern("([0-9]{,4})-([0-9]{,2})-([0-9]{,2})"); dateExp.setPattern("([0-9]{,4})-([0-9]{,2})-([0-9]{,2})");
timeExp.setPattern("([0-9]{,2}):([0-9]{,2}):([0-9]{,2})"); timeExp.setPattern("([0-9]{,2}):([0-9]{,2}):([0-9]{,2})");
dateTimeExp.setPattern(dateExp.pattern() + "T" + timeExp.pattern()); dateTimeExp.setPattern(dateExp.pattern() + 'T' + timeExp.pattern());
} }
void VariantDelegate::paint(QPainter *painter, void VariantDelegate::paint(QPainter *painter,
@ -217,7 +217,7 @@ void VariantDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
value = QSize(sizeExp.cap(1).toInt(), sizeExp.cap(2).toInt()); value = QSize(sizeExp.cap(1).toInt(), sizeExp.cap(2).toInt());
break; break;
case QVariant::StringList: case QVariant::StringList:
value = text.split(","); value = text.split(',');
break; break;
case QVariant::Time: case QVariant::Time:
{ {

View File

@ -421,23 +421,23 @@ void AddressBook::exportAsVCard()
//! [export function part2] //! [export function part2]
//! [export function part3] //! [export function part3]
out << "BEGIN:VCARD" << "\n"; out << "BEGIN:VCARD" << '\n';
out << "VERSION:2.1" << "\n"; out << "VERSION:2.1" << '\n';
out << "N:" << lastName << ";" << firstName << "\n"; out << "N:" << lastName << ';' << firstName << '\n';
if (!nameList.isEmpty()) if (!nameList.isEmpty())
out << "FN:" << nameList.join(' ') << "\n"; out << "FN:" << nameList.join(' ') << '\n';
else else
out << "FN:" << firstName << "\n"; out << "FN:" << firstName << '\n';
//! [export function part3] //! [export function part3]
//! [export function part4] //! [export function part4]
address.replace(";", "\\;", Qt::CaseInsensitive); address.replace(";", "\\;", Qt::CaseInsensitive);
address.replace("\n", ";", Qt::CaseInsensitive); address.replace('\n', ";", Qt::CaseInsensitive);
address.replace(",", " ", Qt::CaseInsensitive); address.replace(",", " ", Qt::CaseInsensitive);
out << "ADR;HOME:;" << address << "\n"; out << "ADR;HOME:;" << address << '\n';
out << "END:VCARD" << "\n"; out << "END:VCARD" << '\n';
QMessageBox::information(this, tr("Export Successful"), QMessageBox::information(this, tr("Export Successful"),
tr("\"%1\" has been exported as a vCard.").arg(name)); tr("\"%1\" has been exported as a vCard.").arg(name));

View File

@ -83,7 +83,7 @@ bool MyModel::setData(const QModelIndex & index, const QVariant & value, int rol
{ {
for(int col= 0; col < COLS; col++) for(int col= 0; col < COLS; col++)
{ {
result += m_gridData[row][col] + " "; result += m_gridData[row][col] + ' ';
} }
} }
emit editCompleted( result ); emit editCompleted( result );

View File

@ -276,7 +276,7 @@ void Calculator::pointClicked()
{ {
if (waitingForOperand) if (waitingForOperand)
display->setText("0"); display->setText("0");
if (!display->text().contains(".")) if (!display->text().contains('.'))
display->setText(display->text() + tr(".")); display->setText(display->text() + tr("."));
waitingForOperand = false; waitingForOperand = false;
} }

View File

@ -79,7 +79,7 @@ void parseHtmlFile(QTextStream &out, const QString &fileName) {
} }
//! [2] //! [2]
out << " Title: \"" << title << "\"" << endl out << " Title: \"" << title << '"' << endl
<< " Number of paragraphs: " << paragraphCount << endl << " Number of paragraphs: " << paragraphCount << endl
<< " Number of links: " << links.size() << endl << " Number of links: " << links.size() << endl
<< " Showing first few links:" << endl; << " Showing first few links:" << endl;

View File

@ -81,8 +81,8 @@ QString XbelGenerator::escapedAttribute(const QString &str)
{ {
QString result = escapedText(str); QString result = escapedText(str);
result.replace("\"", "&quot;"); result.replace("\"", "&quot;");
result.prepend("\""); result.prepend(QLatin1Char('"'));
result.append("\""); result.append(QLatin1Char('"'));
return result; return result;
} }

View File

@ -176,7 +176,7 @@ QMap<int, int> map;
... ...
QMap<int, int>::const_iterator i; QMap<int, int>::const_iterator i;
for (i = map.constBegin(); i != map.constEnd(); ++i) for (i = map.constBegin(); i != map.constEnd(); ++i)
qDebug() << i.key() << ":" << i.value(); qDebug() << i.key() << ':' << i.value();
//! [13] //! [13]
@ -236,7 +236,7 @@ foreach (const QString &str, list) {
QMap<QString, int> map; QMap<QString, int> map;
... ...
foreach (const QString &str, map.keys()) foreach (const QString &str, map.keys())
qDebug() << str << ":" << map.value(str); qDebug() << str << ':' << map.value(str);
//! [19] //! [19]
@ -245,7 +245,7 @@ QMultiMap<QString, int> map;
... ...
foreach (const QString &str, map.uniqueKeys()) { foreach (const QString &str, map.uniqueKeys()) {
foreach (int i, map.values(str)) foreach (int i, map.values(str))
qDebug() << str << ":" << i; qDebug() << str << ':' << i;
} }
//! [20] //! [20]

View File

@ -220,7 +220,7 @@ for (i = hash.begin(); i != hash.end(); ++i)
//! [19] //! [19]
QHash<QString, int>::iterator i = hash.begin(); QHash<QString, int>::iterator i = hash.begin();
while (i != hash.end()) { while (i != hash.end()) {
if (i.key().startsWith("_")) if (i.key().startsWith('_'))
i = hash.erase(i); i = hash.erase(i);
else else
++i; ++i;
@ -233,7 +233,7 @@ QHash<QString, int>::iterator i = hash.begin();
while (i != hash.end()) { while (i != hash.end()) {
QHash<QString, int>::iterator prev = i; QHash<QString, int>::iterator prev = i;
++i; ++i;
if (prev.key().startsWith("_")) if (prev.key().startsWith('_'))
hash.erase(prev); hash.erase(prev);
} }
//! [20] //! [20]
@ -242,7 +242,7 @@ while (i != hash.end()) {
//! [21] //! [21]
// WRONG // WRONG
while (i != hash.end()) { while (i != hash.end()) {
if (i.key().startsWith("_")) if (i.key().startsWith('_'))
hash.erase(i); hash.erase(i);
++i; ++i;
} }

View File

@ -128,7 +128,7 @@ QLinkedList<QString> list;
... ...
QLinkedList<QString>::iterator i = list.begin(); QLinkedList<QString>::iterator i = list.begin();
while (i != list.end()) { while (i != list.end()) {
if ((*i).startsWith("_")) if ((*i).startsWith('_'))
i = list.erase(i); i = list.erase(i);
else else
++i; ++i;
@ -141,7 +141,7 @@ QLinkedList<QString>::iterator i = list.begin();
while (i != list.end()) { while (i != list.end()) {
QLinkedList<QString>::iterator previous = i; QLinkedList<QString>::iterator previous = i;
++i; ++i;
if ((*previous).startsWith("_")) if ((*previous).startsWith('_'))
list.erase(previous); list.erase(previous);
} }
//! [11] //! [11]
@ -150,7 +150,7 @@ while (i != list.end()) {
//! [12] //! [12]
// WRONG // WRONG
while (i != list.end()) { while (i != list.end()) {
if ((*i).startsWith("_")) if ((*i).startsWith('_'))
list.erase(i); list.erase(i);
++i; ++i;
} }

View File

@ -234,7 +234,7 @@ for (i = map.begin(); i != map.end(); ++i)
//! [20] //! [20]
QMap<QString, int>::iterator i = map.begin(); QMap<QString, int>::iterator i = map.begin();
while (i != map.end()) { while (i != map.end()) {
if (i.key().startsWith("_")) if (i.key().startsWith('_'))
i = map.erase(i); i = map.erase(i);
else else
++i; ++i;
@ -247,7 +247,7 @@ QMap<QString, int>::iterator i = map.begin();
while (i != map.end()) { while (i != map.end()) {
QMap<QString, int>::iterator prev = i; QMap<QString, int>::iterator prev = i;
++i; ++i;
if (prev.key().startsWith("_")) if (prev.key().startsWith('_'))
map.erase(prev); map.erase(prev);
} }
//! [21] //! [21]
@ -256,7 +256,7 @@ while (i != map.end()) {
//! [22] //! [22]
// WRONG // WRONG
while (i != map.end()) { while (i != map.end()) {
if (i.key().startsWith("_")) if (i.key().startsWith('_'))
map.erase(i); map.erase(i);
++i; ++i;
} }

View File

@ -777,10 +777,10 @@ void Widget::splitCaseSensitiveFunction()
//! [62] //! [62]
QString str = "a,,b,c"; QString str = "a,,b,c";
QStringList list1 = str.split(","); QStringList list1 = str.split(',');
// list1: [ "a", "", "b", "c" ] // list1: [ "a", "", "b", "c" ]
QStringList list2 = str.split(",", QString::SkipEmptyParts); QStringList list2 = str.split(',', QString::SkipEmptyParts);
// list2: [ "a", "b", "c" ] // list2: [ "a", "b", "c" ]
//! [62] //! [62]
} }

View File

@ -82,7 +82,7 @@ Widget::Widget(QWidget *parent)
//! [5] //! [6] //! [5] //! [6]
QStringList list; QStringList list;
//! [5] //! [5]
list = str.split(","); list = str.split(',');
// list: ["Arial", "Helvetica", "Times", "Courier"] // list: ["Arial", "Helvetica", "Times", "Courier"]
//! [6] //! [6]

View File

@ -60,7 +60,7 @@ int main(int argc, char **argv)
QString sizes; QString sizes;
foreach (int points, database.smoothSizes(family, style)) foreach (int points, database.smoothSizes(family, style))
sizes += QString::number(points) + " "; sizes += QString::number(points) + ' ';
styleItem->setText(1, sizes.trimmed()); styleItem->setText(1, sizes.trimmed());
} }

View File

@ -147,7 +147,7 @@ namespace QTest {
{ {
QByteArray ba = "MyPoint("; QByteArray ba = "MyPoint(";
ba += QByteArray::number(point.x()) + ", " + QByteArray::number(point.y()); ba += QByteArray::number(point.x()) + ", " + QByteArray::number(point.y());
ba += ")"; ba += ')';
return qstrdup(ba.data()); return qstrdup(ba.data());
} }
} }

View File

@ -174,7 +174,7 @@ bool Handler::characters (const QString &chars)
bool Handler::fatalError (const QXmlParseException & exception) bool Handler::fatalError (const QXmlParseException & exception)
{ {
qWarning() << "Fatal error on line" << exception.lineNumber() qWarning() << "Fatal error on line" << exception.lineNumber()
<< ", column" << exception.columnNumber() << ":" << ", column" << exception.columnNumber() << ':'
<< exception.message(); << exception.message();
return false; return false;

View File

@ -78,7 +78,7 @@ int main(int argc, char **argv)
for (int i = 0; i < items; ++i) { for (int i = 0; i < items; ++i) {
for (int j = 0; j < indentations[i]; ++j) for (int j = 0; j < indentations[i]; ++j)
std::cout << " "; std::cout << ' ';
std::cout << names[i].toLocal8Bit().constData() << std::endl; std::cout << names[i].toLocal8Bit().constData() << std::endl;
} }
} }