Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Unsolved Best way to save program data

    General and Desktop
    embedded linux
    6
    10
    2763
    Loading More Posts
    • 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.
    • T
      TMJJ001 last edited by

      Hi all,

      I will shortly explain my situation.
      I have written a qt application to read data from a can bus. When specific data arrives at the embedded system, I would like to run certain piece of code. The user of the system should be able to program this code graphically.

      The problem I'm facing now:
      What is the best way to save those settings (graphical code)?

      • Should I use A small database
      • Can I put it into a .ini file
      • Can I put it into a text file
      • Other possibilities?

      Thanks in advance,
      Kind regards

      G jsulm raven-worx 3 Replies Last reply Reply Quote 0
      • G
        Gourmet @TMJJ001 last edited by Gourmet

        @TMJJ001 If you have some "program code" then it can be represented as "tree". Qt has very powerful XML support. Learn it and save your data in XML file as tree. It is fast enough even for large trees. I used it in my other project to save user created complex schemes.

        But this does not relate to Mobile and Embedded...

        T 2 Replies Last reply Reply Quote 5
        • jsulm
          jsulm Lifetime Qt Champion @TMJJ001 last edited by

          @TMJJ001

          • It can be stored in a database, but I would not do it this way
          • No! Ini files are configuration files. What you describe sounds like application data, not configuration
          • Sure you can if you define a format
          • XML as suggested by @Gourmet, your own text/binary format, any other format already available for "graphical code"

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

          1 Reply Last reply Reply Quote 2
          • T
            TMJJ001 @Gourmet last edited by

            @Gourmet

            Thanks for the reply, are you able to show me the direction to go?
            Something like a tutorial or something?
            I was looking on the internet but I'm unable to get started.

            Kind regards

            kshegunov 1 Reply Last reply Reply Quote 0
            • kshegunov
              kshegunov Moderators @TMJJ001 last edited by kshegunov

              I, personally, would go with a small SQLite database. Even large trees can efficiently be represented in linear sets (as an SQL database) by keeping the left and right depth search index as metadata. Not to mention this way you don't need to define the XML structure and write the parsing. As for graphs, that's entirely different kettle of fish, so perhaps you should elaborate on what this graphical code would need to actually store.

              Read and abide by the Qt Code of Conduct

              1 Reply Last reply Reply Quote 3
              • T
                TMJJ001 @Gourmet last edited by

                @Gourmet

                Hi, I try to go with xml.

                I was looking for some good tutorials on how to learn it. I found the following:
                https://www.youtube.com/watch?v=NzQwJdcdRKE

                Now when I try to load, I can't. I can't find my mistake.
                Anybody an idea?

                    // DOM reading xml file
                    QDomDocument document("MachineSetting");
                
                    //load xml file
                
                    QFile file("MachineSetting.xml");
                    if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
                    {
                        qDebug() <<"Failed to open file";
                        return;
                    }
                    else
                    {
                        if(!document.setContent(&file))
                        {
                                qDebug()<<"Failed to load document";
                                return;
                        }
                        file.close();
                    }
                

                After running the function it says:
                Failed to load document.

                Any idea?

                I a

                jsulm 1 Reply Last reply Reply Quote 0
                • SGaist
                  SGaist Lifetime Qt Champion last edited by

                  Hi,

                  setContent as several more parameters that allow you to get information about what is going wrong. You should use them to check what is going on.

                  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 Reply Quote 0
                  • jsulm
                    jsulm Lifetime Qt Champion @TMJJ001 last edited by

                    @TMJJ001 Can you show the content of MachineSetting.xml ?

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

                    T 1 Reply Last reply Reply Quote 2
                    • raven-worx
                      raven-worx Moderators @TMJJ001 last edited by raven-worx

                      @TMJJ001 said in Best way to save program data:

                      What is the best way to save those settings (graphical code)?

                      to make the suggestions complete i would say to use binary format :D
                      You can use QDataStream class for that.
                      Save your data variables, lists, etc. into a file with QDataStream. Then read them back in in the same order you've written them.

                      For custom types you need to create the corresponding stream operators (see the docs).

                      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                      If you have a question please use the forum so others can benefit from the solution in the future

                      1 Reply Last reply Reply Quote 3
                      • T
                        TMJJ001 @jsulm last edited by

                        @jsulm

                        Sorry for the late reply.
                        There was an error in the .xml file and not in my code!
                        So I managed to solve the error.

                        Code works like a charm!

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post