PDA

View Full Version : Generating Customized project files in Qt



Raghaw
19th March 2015, 04:50
Hi ,

In my Current requirement i would like to create a a customized project file which my application can load in future.The project file will be specific to my application only .It will contain all the paths of the created components as items represent unique directory.There will be loading of some other tools from my application which will also generate some files and there record is also to be maintained in my project file.This project file can be loaded also by my application.

I could use QSettings way , but the problem is the file extension of QSettings file will be either .ini or .conf, as compared to my project file extension which will be let say .amu.

I can do this also using XML way.But can any body suggest some other goof way to achieve this functionality.

Thanks.

jefftee
19th March 2015, 06:23
Why do you care what the file extension is for your application settings?

If you really want to use your .amu file extension and have control over the contents/format of the settings, you can read/write the contents yourself using either serialized Qt objects, XML, JSON, or any other format you wish. If you decide to do this, then the responsibility is yours to manage the contents/format of the data.

I would suggest that you use QSettings with the QSettings::NativeFormat, which would be standard for the OS type your application is running on. This would also allow users to edit your application settings using the native OS tools like Xcode plist editor on Mac, a text editor for INI files, or regedit for Windows applications.

You can of course choose to reinvent the wheel, it's just not clear why you would want to do this.

Edit: You could also use a database like SQLITE to store all of these settings. If your app already uses a database, then adding a settings or preferences table would be trivial to implement. With SQLITE, you can also name the file whatever you want, so you could use the .amu file type as well.

Regards,

Jeff

anda_skoa
19th March 2015, 08:10
I could use QSettings way , but the problem is the file extension of QSettings file will be either .ini or .conf, as compared to my project file extension which will be let say .amu.

Doesn't QSettings have a constructor that lets you pass a filename?

Cheers,
_

d_stranz
19th March 2015, 15:31
You might also look at this post (http://www.qtcentre.org/threads/59733-QMetaType-dynamic-object-creation-and-initialization) where I posted code that implements serialization of QSettings using XML. You can use any QIODevice-based storage, so if you use a file, you can name it anything you want.