Results 1 to 2 of 2

Thread: Config file usage in Qt

  1. #1
    Join Date
    Aug 2013
    Posts
    25
    Thanks
    7
    Qt products
    Qt5

    Default Config file usage in Qt

    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

  2. #2
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Config file usage in Qt

    Quote Originally Posted by gfernandes View Post
    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.

    Quote Originally Posted by gfernandes View Post
    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
    Last edited by jefftee; 26th June 2014 at 20:22.

  3. The following user says thank you to jefftee for this useful post:

    gfernandes (30th June 2014)

Similar Threads

  1. Update GUI from Config File
    By SiddhantR in forum Newbie
    Replies: 16
    Last Post: 19th September 2013, 01:27
  2. Qt Application and config File?
    By snakemedia in forum Qt Programming
    Replies: 1
    Last Post: 27th February 2011, 09:12
  3. QSettings, my own format of config-file
    By IPFreely in forum Qt Programming
    Replies: 2
    Last Post: 14th November 2007, 21:07
  4. config file class
    By feizhou in forum Qt Programming
    Replies: 2
    Last Post: 23rd November 2006, 08:49
  5. Config file parsing
    By Vash5556 in forum Qt Programming
    Replies: 2
    Last Post: 11th September 2006, 00:11

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.