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. Best way to save program data
QtWS25 Last Chance

Best way to save program data

Scheduled Pinned Locked Moved Unsolved General and Desktop
embedded linux
10 Posts 6 Posters 4.0k Views
  • 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 Offline
    T Offline
    TMJJ001
    wrote on 21 Mar 2018, 18:56 last edited by
    #1

    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 J R 3 Replies Last reply 21 Mar 2018, 19:59
    0
    • T TMJJ001
      21 Mar 2018, 18:56

      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 Offline
      G Offline
      Gourmet
      wrote on 21 Mar 2018, 19:59 last edited by Gourmet
      #2

      @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 26 Mar 2018, 19:11
      5
      • T TMJJ001
        21 Mar 2018, 18:56

        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

        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 22 Mar 2018, 06:20 last edited by
        #3

        @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
        2
        • G Gourmet
          21 Mar 2018, 19:59

          @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 Offline
          T Offline
          TMJJ001
          wrote on 26 Mar 2018, 19:11 last edited by
          #4

          @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

          K 1 Reply Last reply 26 Mar 2018, 19:20
          0
          • T TMJJ001
            26 Mar 2018, 19:11

            @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

            K Offline
            K Offline
            kshegunov
            Moderators
            wrote on 26 Mar 2018, 19:20 last edited by kshegunov
            #5

            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
            3
            • G Gourmet
              21 Mar 2018, 19:59

              @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 Offline
              T Offline
              TMJJ001
              wrote on 28 Mar 2018, 19:19 last edited by
              #6

              @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

              J 1 Reply Last reply 29 Mar 2018, 05:46
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on 28 Mar 2018, 19:47 last edited by
                #7

                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
                0
                • T TMJJ001
                  28 Mar 2018, 19:19

                  @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

                  J Offline
                  J Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on 29 Mar 2018, 05:46 last edited by
                  #8

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

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

                  T 1 Reply Last reply 5 Apr 2018, 05:56
                  2
                  • T TMJJ001
                    21 Mar 2018, 18:56

                    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

                    R Offline
                    R Offline
                    raven-worx
                    Moderators
                    wrote on 29 Mar 2018, 06:56 last edited by raven-worx
                    #9

                    @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
                    3
                    • J jsulm
                      29 Mar 2018, 05:46

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

                      T Offline
                      T Offline
                      TMJJ001
                      wrote on 5 Apr 2018, 05:56 last edited by
                      #10

                      @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
                      0

                      1/10

                      21 Mar 2018, 18:56

                      • Login

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