summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2023-02-23 11:34:16 +0100
committerMarc Mutz <marc.mutz@qt.io>2023-04-11 12:37:36 +0000
commit9834e80833783357743b2a5abe3071760638effb (patch)
tree63481a13dad1064b1ced7a37b0eb54cb27f397e4 /examples
parent26f0657feedd756ed99aab4f3262c244960909d1 (diff)
downloadqtbase-9834e80833783357743b2a5abe3071760638effb.tar.gz
savegame ex.: give some TLC to main()
- include what you use - make 'args' const, so we don't detach in op[] - make boolean variables const - use QString::compare(lhs, rhs, Qt::CaseInsensitive) instead of lhs.toLower() == rhs - use new _L1 UDL - fix indentation of a return statement Pick-to: 6.5 Change-Id: If9da4fbe975d9a97939ea01558b2a8cef7ad3a24 Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'examples')
-rw-r--r--examples/corelib/serialization/savegame/main.cpp19
1 files changed, 11 insertions, 8 deletions
diff --git a/examples/corelib/serialization/savegame/main.cpp b/examples/corelib/serialization/savegame/main.cpp
index 408b08dbc9..f97b0d595f 100644
--- a/examples/corelib/serialization/savegame/main.cpp
+++ b/examples/corelib/serialization/savegame/main.cpp
@@ -4,25 +4,28 @@
#include "game.h"
#include <QCoreApplication>
+#include <QStringList>
+#include <QString>
#include <QTextStream>
+using namespace Qt::StringLiterals; // for _L1
+
//! [0]
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
- QStringList args = QCoreApplication::arguments();
- bool newGame = true;
- if (args.length() > 1)
- newGame = (args[1].toLower() != QStringLiteral("load"));
- bool json = true;
- if (args.length() > 2)
- json = (args[2].toLower() != QStringLiteral("binary"));
+
+ const QStringList args = QCoreApplication::arguments();
+ const bool newGame
+ = args.size() <= 1 || QString::compare(args[1], "load"_L1, Qt::CaseInsensitive) == 0;
+ const bool json
+ = args.size() <= 2 || QString::compare(args[2], "binary"_L1, Qt::CaseInsensitive) == 0;
Game game;
if (newGame)
game.newGame();
else if (!game.loadGame(json ? Game::Json : Game::Binary))
- return 1;
+ return 1;
// Game is played; changes are made...
//! [0]
//! [1]