Writing object variables to file qjason



  • 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


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    What about using a database for that kind of information ?



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


  • Moderators

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



  • 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)



  • 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 :)


  • Qt Champions 2016

    @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


  • Moderators

    @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 :-)


Log in to reply