Best way to save program data
-
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 -
@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...
-
- 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"
-
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.
-
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=NzQwJdcdRKENow 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
-
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. -
@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).