diff options
author | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2018-02-22 09:19:56 +0100 |
---|---|---|
committer | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2018-02-22 09:19:56 +0100 |
commit | 9f33b84b0937a53e8e31e0c1e34506eecef6f2e4 (patch) | |
tree | 91e9bac96d61c08babd5b6415f276d44888e79dd /examples | |
parent | 4cbc7f798017d76e018dc3f04968703624b6a6cf (diff) | |
parent | b97765efd452921f75c1d04820c4b5e9e9d49100 (diff) |
Merge remote-tracking branch 'origin/5.11' into dev
Change-Id: Iec636692e8b7d1fe1bc0476e49c5054a5892d639
Diffstat (limited to 'examples')
-rw-r--r-- | examples/corelib/serialization/savegame/doc/src/savegame.qdoc | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/examples/corelib/serialization/savegame/doc/src/savegame.qdoc b/examples/corelib/serialization/savegame/doc/src/savegame.qdoc index 06e70680c6..a35f763430 100644 --- a/examples/corelib/serialization/savegame/doc/src/savegame.qdoc +++ b/examples/corelib/serialization/savegame/doc/src/savegame.qdoc @@ -26,7 +26,7 @@ ****************************************************************************/ /*! - \example json/savegame + \example serialization/savegame \title JSON Save Game Example \brief The JSON Save Game example demonstrates how to save and load a @@ -50,12 +50,12 @@ It provides read() and write() functions to serialise its member variables. - \snippet json/savegame/character.h 0 + \snippet serialization/savegame/character.h 0 Of particular interest to us are the read and write function implementations: - \snippet json/savegame/character.cpp 0 + \snippet serialization/savegame/character.cpp 0 In the read() function, we assign Character's members values from the QJsonObject argument. You can use either \l QJsonObject::operator[]() or @@ -64,7 +64,7 @@ check if the keys are valid before attempting to read them with QJsonObject::contains(). - \snippet json/savegame/character.cpp 1 + \snippet serialization/savegame/character.cpp 1 In the write() function, we do the reverse of the read() function; assign values from the Character object to the JSON object. As with accessing @@ -74,13 +74,13 @@ Next up is the Level class: - \snippet json/savegame/level.h 0 + \snippet serialization/savegame/level.h 0 We want to have several levels in our game, each with several NPCs, so we keep a QVector of Character objects. We also provide the familiar read() and write() functions. - \snippet json/savegame/level.cpp 0 + \snippet serialization/savegame/level.cpp 0 Containers can be written and read to and from JSON using QJsonArray. In our case, we construct a QJsonArray from the value associated with the key @@ -94,7 +94,7 @@ element is used as the key to construct the container when reading it back in. - \snippet json/savegame/level.cpp 1 + \snippet serialization/savegame/level.cpp 1 Again, the write() function is similar to the read() function, except reversed. @@ -102,7 +102,7 @@ Having established the Character and Level classes, we can move on to the Game class: - \snippet json/savegame/game.h 0 + \snippet serialization/savegame/game.h 0 First of all, we define the \c SaveFormat enum. This will allow us to specify the format in which the game should be saved: \c Json or \c Binary. @@ -112,12 +112,12 @@ The read() and write() functions are used by saveGame() and loadGame(). - \snippet json/savegame/game.cpp 0 + \snippet serialization/savegame/game.cpp 0 To setup a new game, we create the player and populate the levels and their NPCs. - \snippet json/savegame/game.cpp 1 + \snippet serialization/savegame/game.cpp 1 The first thing we do in the read() function is tell the player to read itself. We then clear the level array so that calling loadGame() on the @@ -125,11 +125,11 @@ We then populate the level array by reading each Level from a QJsonArray. - \snippet json/savegame/game.cpp 2 + \snippet serialization/savegame/game.cpp 2 We write the game to JSON similarly to how we write Level. - \snippet json/savegame/game.cpp 3 + \snippet serialization/savegame/game.cpp 3 When loading a saved game in loadGame(), the first thing we do is open the save file based on which format it was saved to; \c "save.json" for JSON, @@ -144,7 +144,7 @@ After constructing the QJsonDocument, we instruct the Game object to read itself and then return \c true to indicate success. - \snippet json/savegame/game.cpp 4 + \snippet serialization/savegame/game.cpp 4 Not surprisingly, saveGame() looks very much like loadGame(). We determine the file extension based on the format, print a warning and return \c false @@ -155,7 +155,7 @@ We are now ready to enter main(): - \snippet json/savegame/main.cpp 0 + \snippet serialization/savegame/main.cpp 0 Since we're only interested in demonstrating \e serialization of a game with JSON, our game is not actually playable. Therefore, we only need @@ -169,7 +169,7 @@ assume that the player had a great time and made lots of progress, altering the internal state of our Character, Level and Game objects. - \snippet json/savegame/main.cpp 1 + \snippet serialization/savegame/main.cpp 1 When the player has finished, we save their game. For demonstration purposes, we can serialize to either JSON or binary. You can examine the |