diff options
author | Tobias Hunger <tobias.hunger@qt.io> | 2019-04-16 16:32:08 +0200 |
---|---|---|
committer | Tobias Hunger <tobias.hunger@qt.io> | 2019-04-16 16:32:08 +0200 |
commit | 6630937e63ae5797487b86743a7733c8ae5cc42c (patch) | |
tree | 3d53dacf6430f9099e1fb20835881205de674961 /examples/xml/htmlinfo | |
parent | 37ed6dae00640f9cc980ffda05347c12a7eb5d7e (diff) | |
parent | c7af193d2e49e9f10b86262e63d8d13abf72b5cf (diff) |
Merge commit 'dev' into 'wip/cmake-merge'
Change-Id: I176c40d031be26a1dd1cf08843e448a660598783
Diffstat (limited to 'examples/xml/htmlinfo')
-rw-r--r-- | examples/xml/htmlinfo/htmlinfo.pro | 3 | ||||
-rw-r--r-- | examples/xml/htmlinfo/main.cpp | 26 |
2 files changed, 14 insertions, 15 deletions
diff --git a/examples/xml/htmlinfo/htmlinfo.pro b/examples/xml/htmlinfo/htmlinfo.pro index e106c69b52..8fea3b38dd 100644 --- a/examples/xml/htmlinfo/htmlinfo.pro +++ b/examples/xml/htmlinfo/htmlinfo.pro @@ -1,10 +1,9 @@ SOURCES += main.cpp QT -= gui -CONFIG -= app_bundle RESOURCES = resources.qrc -win32: CONFIG += console +CONFIG += cmdline # install target.path = $$[QT_INSTALL_EXAMPLES]/xml/htmlinfo diff --git a/examples/xml/htmlinfo/main.cpp b/examples/xml/htmlinfo/main.cpp index 6591c3ac91..22bf36f33c 100644 --- a/examples/xml/htmlinfo/main.cpp +++ b/examples/xml/htmlinfo/main.cpp @@ -50,7 +50,8 @@ #include <QtCore> -void parseHtmlFile(QTextStream &out, const QString &fileName) { +void parseHtmlFile(QTextStream &out, const QString &fileName) +{ QFile file(fileName); out << "Analysis of HTML file: " << fileName << endl; @@ -71,11 +72,11 @@ void parseHtmlFile(QTextStream &out, const QString &fileName) { while (!reader.atEnd()) { reader.readNext(); if (reader.isStartElement()) { - if (reader.name() == "title") + if (reader.name() == QLatin1String("title")) title = reader.readElementText(); - else if(reader.name() == "a") - links.append(reader.attributes().value("href").toString()); - else if(reader.name() == "p") + else if (reader.name() == QLatin1String("a")) + links.append(reader.attributes().value(QLatin1String("href")).toString()); + else if (reader.name() == QLatin1String("p")) ++paragraphCount; } } @@ -94,10 +95,10 @@ void parseHtmlFile(QTextStream &out, const QString &fileName) { << " Number of links: " << links.size() << endl << " Showing first few links:" << endl; - while(links.size() > 5) + while (links.size() > 5) links.removeLast(); - foreach(QString link, links) + for (const QString &link : qAsConst(links)) out << " " << link << endl; out << endl << endl; } @@ -108,11 +109,10 @@ int main(int argc, char **argv) QCoreApplication app(argc, argv); // get a list of all html files in the current directory - QStringList filter; - filter << "*.htm"; - filter << "*.html"; + const QStringList filter = { QStringLiteral("*.htm"), + QStringLiteral("*.html") }; - QStringList htmlFiles = QDir(":/").entryList(filter, QDir::Files); + const QStringList htmlFiles = QDir(QStringLiteral(":/")).entryList(filter, QDir::Files); QTextStream out(stdout); @@ -122,8 +122,8 @@ int main(int argc, char **argv) } // parse each html file and write the result to file/stream - foreach(QString file, htmlFiles) - parseHtmlFile(out, ":/" + file); + for (const QString &file : htmlFiles) + parseHtmlFile(out, QStringLiteral(":/") + file); return 0; } |