Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Writing object variables to file qjason

Writing object variables to file qjason

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 5 Posters 2.2k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sterling
    wrote on last edited by
    #1

    Hi,

    I am currently doing a school project.

    We are creating a snake game, not using qml.
    I am now stuck on writing username and score to file in such a way that I can easily retrieve the information and list it in a table later on. I have been looking into this http://qjson.sourceforge.net/usage/ but I get errors when I make a class implemented this way. And I can not find anything on implementation, only headerfiles in the tutorial. Any advice would be appreciated.

    0_1492554031021_upload-5da0eaff-36b0-474e-ae5b-d1da11696ace
    0_1492554057322_upload-fdfe2fdb-8942-437b-9abb-0ebbc4d4f738

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      What about using a database for that kind of information ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sterling
        wrote on last edited by
        #3

        I would love to!!! :)
        I need to deliver this project fully functional in a zip folder. Is this possible, with a database? :)

        jsulmJ 1 Reply Last reply
        0
        • S sterling

          I would love to!!! :)
          I need to deliver this project fully functional in a zip folder. Is this possible, with a database? :)

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @sterling Yes, use SQLite - it stores the data in a file. Qt supports SQLite.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by
            #5

            SQL to save the top scores seams a huge overkill. One of my first projects in Qt was a snake game using QWidgets, looking at the code now makes me want to puke but it worked (and I still can't beat the rat in the last level of difficulty 😜). In that case I just used a binary file see https://github.com/VSRonin/SnaQe/blob/master/Opzioni.cpp#L166 (sorry for code written in italian)

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            1 Reply Last reply
            2
            • S Offline
              S Offline
              sterling
              wrote on last edited by
              #6

              Thank you all so much! You have been very helpful. :)

              I have been looking into sql lite, as it would be interresting.When I looked into it I got the impression I still needed external sources.
              So I skipped it.
              I will look into your code VRonin.
              Thank god for google translate :)

              mrjjM jsulmJ 2 Replies Last reply
              0
              • S sterling

                Thank you all so much! You have been very helpful. :)

                I have been looking into sql lite, as it would be interresting.When I looked into it I got the impression I still needed external sources.
                So I skipped it.
                I will look into your code VRonin.
                Thank god for google translate :)

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by mrjj
                #7

                @sterling
                Hi
                For the last part. a zip file. yes its possible.
                You just need a so called deployment folder with all Qt dlls and some sub folders. and then your .exe.
                http://doc.qt.io/qt-5/windows-deployment.html
                http://www.tripleboot.org/?p=138

                For using json, this might be of use
                http://doc.qt.io/qt-5/qtcore-json-savegame-example.html

                1 Reply Last reply
                2
                • S sterling

                  Thank you all so much! You have been very helpful. :)

                  I have been looking into sql lite, as it would be interresting.When I looked into it I got the impression I still needed external sources.
                  So I skipped it.
                  I will look into your code VRonin.
                  Thank god for google translate :)

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @sterling said in Writing object variables to file qjason:

                  I still needed external sources

                  What external sources do you mean? Qt already supports SQLite out of the box.
                  But it is just a note - I don't want to force you to use SQLite :-)

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  3

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved