Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Nontrivial question: outlining what I need to learn.



  • Up until now, I've been sort of blindly stumbling around trying to put together the program I'm aiming to create, but while I've made a ton of progress, I don't think this is the best way for me to be learning. To give you an example, I'm trying to learn how to implement save functionality, and in doing so I've found that I don't know which method of saving to use(SQL? XML? JSON? Something else?) , on top of constantly finding more base-level functionality that I have to learn to use these things (Q_ENUM() is a good example; nothing in the C++ site I'm using has told me why I would need something like that so far). At the very least, I'd like to have some idea of what basic concepts I should learn, as someone who only knows raw console-based C++, before moving onto more advanced ways to implement those concepts (rather than working backward).

    Here's my outline I've been using of what I want this particular widget to do (I plan to connect it to other widgets in a main program later, but baby steps):

    1. Create a large central 'canvas'
    2. Allow users to create objects I'm calling 'blocks', which will anchor and connect to each other.
      a. Blocks are going to be used to construct a reusable formula that will be calculated later by a different widget.
      b. Blocks have to 'branch' off the initial Block. No loose Blocks.
      c. What Blocks you can use(number and type) will be limited by external numbers.
      d. Blocks will only be able to connect in certain ways (say, BlockA has triangle-connectors on the right side, BlockB will only be able to connect if it has triangle connectors on the left side).
      e. Block saving should be usable both for extracting the formula by a connected widget, as well as usable to reconstruct the saved Block construction for editing.
    3. Provide various tools to create and manage the Blocks
    4. Provide a way to switch to the main screen/other widgets.

    I already have an idea of what the UI should look like. Luckily, with Qt's UI designer, that much is the easy part, and placeholder art can make the UI usable. I've also figured out how to create a graphics screen, thanks to the examples I've looked at. Here's what I have so far:

    • Main window with embedded view for graphic scene.
    • QGraphicsItem derived class called Block, which is an abstract class for other types of Blocks to override with their own functionality.
    • A Block derived class is created in the scene, and I can move it around.

    It doesn't look like I've accomplished a lot, but I feel like it's a ton for the amount of hurdles I've overcome getting here. I'm just hoping to lessen those hurdles by learning things in some sort of proper order, so that I can both learn new things that are based on what I already know, as well as be able to separate unneeded functionality from the examples so I can implement functionality that matches what I need instead.



  • JSON and XML are ways to format your data. SQL is a language to interface a database and retrieve data, specifically relational databases. Databases are a container for your saved data. Saving a JSON string in a text file can be considered saving data, whats more is that it's in a format that you or someone else can do something with.

    Addressing your "saving"

    How do you want to store the data? Are you looking for a crude approach i.e. saving some text strings which contain your data in some format like JSON (if that is it then look up QJson and writing to text files), or perhaps a structured (or non structured) database approach? For your application I would actually look into NoSQL database first. You may also want to look at the save game examples in the Qt Creator which uses JSON to save the data (somewhere, I can't recall where, my guess is a local file). Something like JSON and NoSQL would be a good area for you to look at because you have really unique non-consistent "blocks". If you go with a relational database it will be hard to define a structure to encompass your blocks. Also, think of Qts JSON libraries as a means to transfer your block class data into a format that is expressible to other targets, like a NoSQL database solution for example. In general I would shy away from XML formatting.

    If I were you I would take some time off of Qt and do some diving into something like MS SQL Server, MySQL, MongoDB, etc (check this out, both relational and NoSQL capabilities). I know you can download free of charge a lot of these softwares and start playing around, watching videos, and understanding it. It will at least provide you with a broader perspective and hopefully lead you closer to deciding what works best for you.



  • Alright, I'll check those out, thanks a ton. I wasn't even sure where to begin to start learning what these were. The Qt documentation isn't really helpful in directing you if you don't know what all the options are from the get-go. Incredibly well documented for if you know what everything is, but not so much for someone who doesn't know the basic premises of what's expected to be known already on top of c++.



  • Googling about SQL, noSQL, and databases in general, I've come to the conclusion that I don't know enough choose a direction to go, and that I don't know where I would go for that. NoSQL is apparently not a standardized language like C++ or a resource like Qt, but rather a method of creating a non-relational database. And I don't know exactly what that is, in computer terms; I know the basic term database's use as a location where data is stored, but I don't know more than that.

    More than one source implies that databases are different than locally stored files; that also indicates to me that they're stored on web servers, and while online access and savefile storage for my program would be great to get to eventually, it's outside of the scope of what I'm currently trying to do (and I wouldn't have the funds for one anyway). JSON seems like it would be functional, although it doesn't seem to me to be the standard form of file storage, just one that has more uses such as the ability to be edited (config files would make sense here). I have to wonder if XML is a format intended to have similar extra uses, and if there's a simpler option than that.



  • Consider writing JSON or XML out to some files using something like QFile. You can read them on load and set your class data from what you read.

    SQLite is also very very good imo for local data storage, however I see problems with the structure of the data you are storing, its seems like it could be very unstructured, making it difficult to build table(s) that handle that lack of structure, hence my mentioning NoSQL.

    From what I know, XML is going to require more structure. If you want to stay local which it sounds like you do here is what I would look into now.

    1: get the JSON basic, not that hard so should go quick.
    2: get to know QJsonObject/Array/Value/Document

    then I would try to make some small program that does this:

    1. creates some object
    2. appends object into json array
    3. repeats 1 and 2 a few times
    4. creates QJsonDocument from array
    5. use the QJsonDocument you made and QFile and print that out to a text file

    Then try to do that in reverse. You will then see the essence of what you are trying to achieve.

    What is nice is that the JSON array does not require the objects being appended in to be identical, so you can have some objects with properties that others do not. By storing the JSON array you will nicely contain all your objects for unpackaging, otherwise you will have to add some extra logic to read it in.

    I think you will find that once you understand the QJson classes, it will be pretty simple. Good luck.


Log in to reply