This forum has been archived. All content is frozen. Please use KDE Discuss instead.

How to save basic configuration of an application

Tags: None
(comma "," separated)
Tupla
Registered Member
Posts
47
Karma
0
OS
Hello everybody, same as subject, how can I get my application to save and restore basic configuration (such as state of some toggle action, recent files and similar)?
My main window class inherits from KXmlGuiWindow.
Thanks!
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
You need to look at KConfig for this.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
Tupla
Registered Member
Posts
47
Karma
0
OS
Thanks a lot, it worked!
Tupla
Registered Member
Posts
47
Karma
0
OS
Why if I put a function that prompts the user the choice to save file or cancel exiting in queryExit function (overridden from KXmlGuiWindow) and I return false to queryExit (i.e. the Cancel button) the program closes in any case?
With the queryClose it doesn't happen, and the code in both functions it's the same...
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
It may be, that if all windows are closed your application is automatically quit.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
Tupla
Registered Member
Posts
47
Karma
0
OS
In fact it is, but I looked at KMainWindow documentation, in the queryExit function:
Default implementation returns true. Returning false will cancel the exiting. In the latter case, the last window will remain visible.

So if I type CTRL + Q or if I choose "Quit" from the file menu and then "Cancel" to the dialog, it should'n exit the application :-\

There's another interesting thing in queryExit explanation:
It is not recommended to do any user interaction in this function other than indicating severe errors. Better ask the user on queryClose() (see below).

So if the user quit the application by using "Quit", there shouldn't be any interaction or prompt whether to save changes or not? That point isn't clear for me...
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
If "Quit" is pressed then the main application should try to close all windows, and if any fail, then it should not continue.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
Tupla
Registered Member
Posts
47
Karma
0
OS
Mmm... So if I return false from queryQuit, it should not continue closing the application, right?
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
Correct, however all your windows may be closed at this point, so the application will be closed anyway. You should do the check in queryClose as recommended by the documentation.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
Tupla
Registered Member
Posts
47
Karma
0
OS
Ok, thanks! :)


Bookmarks



Who is online

Registered users: Bing [Bot], Evergrowing, Google [Bot], rockscient