PDA

View Full Version : Config file usage in Qt



gfernandes
26th June 2014, 13:43
Hi,

Since I am a beginner in software development I am not sure how to go about static variables in the program.

My approach was to use a configuration file that could be accessed for details like port number, directory path etc. For this I have been using QSettings to access my Config.ini.

I had seen few seniors at work (using visual studio with c++) use Config.xml that they parse at the launch of the application and save it in a structure.

So I was planning to do something similar with my Qt application. I wanted to create a Config.h file with all the global variables, structures. I want my software at bootup to parse this config file (Config.ini) and assign the global variables the corresponding values from the file. I am planning to import this Config.h wherever the global variables are used.

Is this a good approach? Any help or suggestions is appreciated. If you could give me links to examples it would be great.

Thank you

jefftee
26th June 2014, 20:18
Is this a good approach? Any help or suggestions is appreciated. If you could give me links to examples it would be great.

It should certainly be doable, but is there a reason you don't want to use QSettings other than your co-workers use something different? I would use QSettings since Qt provides that functionality (and it's portable too). You can spend more time coding your application functionality rather than mundane parsing of an XML file to set variables.


I wanted to create a Config.h file with all the global variables, structures. I want my software at bootup to parse this config file (Config.ini) and assign the global variables the corresponding values from the file.
You should try to avoid global variables if at all possible. A lot of global variables usually means you don't have good class design and bugs can be hard to track down, etc. Review your objects and see if there isn't a better solution than a bunch of global variables.

Just my humble opinion!

Jeff