qt5base-lts/examples/corelib/serialization/savegame/main.cpp
Marc Mutz 88e8094f18 savegame ex.: fix include order
Includes should be ordered from most specific to most general. This
means that project-specific includes always come before Qt includes.

This example didn't follow that guideline. Fix.

Task-number: QTBUG-108857
Pick-to: 6.5 6.4 6.2 5.15
Change-Id: I42727ff8bdef5336368cde349cbcb8d10bb6289f
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-02-08 08:37:21 +01:00

37 lines
935 B
C++

// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "game.h"
#include <QCoreApplication>
#include <QTextStream>
//! [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"));
Game game;
if (newGame)
game.newGame();
else if (!game.loadGame(json ? Game::Json : Game::Binary))
return 1;
// Game is played; changes are made...
//! [0]
//! [1]
QTextStream(stdout) << "Game ended in the following state:\n";
game.print();
if (!game.saveGame(json ? Game::Json : Game::Binary))
return 1;
return 0;
}
//! [1]