LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-15-2006, 03:53 PM   #1
Ephracis
Senior Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Ubuntu, Debian
Posts: 1,109

Rep: Reputation: 50
Method to store settings


Hi,

I would like it if some of you experienced guys could give me some hints, or show me some reading on how to store settings in a KDE C++ application. I have been thinking about using some sort of readable config-file but I figured that that is not necessary, I could as well store them in binary somewhere. Is there any well-known method on how to approach such a problem? I would like to make my application "KDEish", so that it won't be too much of a hazzle to learn just because I use "my own methods". If you understand what I mean.

Thanks for any reply.
 
Old 01-15-2006, 08:31 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
mozilla file:///<where/your-qt-docs-live>/qt/doc/html/qsettings.html

Don't know whether KDE added anything on top of that.


Cheers,
Tink
 
Old 01-15-2006, 10:41 PM   #3
foo_bar_foo
Senior Member
 
Registered: Jun 2004
Posts: 2,553

Rep: Reputation: 53
example
Code:
KConfig *kconfig = KGlobal::config();
kconfig->setGroup("GeneralStuff");
kconfig->writeEntry("Something",somethings_setting);
kconfig->sync();
reading is just as easy but a little more tricky -- now that you know what it is you can find the docs
Code:
KConfig *kconfig = KGlobal::config();
kconfig->setGroup("GeneralStuff");
somethings_setting = kconfig->readEntry("Something");
since its just a value pair you need casting like
readNumEntry()
readSizeEntry()
readBoolEntry()
and you can set a default for if the read fails like
myOtherClass->setBooleanThingy(kconfig->readBoolEntry("boolean_thingy",false));
or whatever -- KDE is so easy to use it ought to be a crime
 
Old 01-16-2006, 04:55 AM   #4
Ephracis
Senior Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Ubuntu, Debian
Posts: 1,109

Original Poster
Rep: Reputation: 50
I like the KConfig way. I have one problem with it, tho. Since my application is Qt4 it seems I cannot use it.

After a qmake-qt4 -project && qmake-qt4 I have a Makefile done and ready. kconfig.h (which I assume is the file I need to include if I want to use KConfig) exists in /usr/include/kde, so I add -I/usr/include/kde to the INCPATH in the Makefile. However, I also need to add -I/usr/include/qt3 since some headers (like qstrlist.h) is needed by the kconfig-headers.

I have the same problem when trying to use KParts, which also forces me to include /usr/include/qt3. With this dir included in the Makefile I get following the errors:
Code:
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_CORE_LIB -DQT_GUI_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtCore -I/usr/include/qt4 -I. -Isrc -I. -I. -I/usr/include/kde -I/usr/include/qt3 -o main.o src/main.cpp
/usr/include/qt3/qtextstream.h:53: error: invalid function declaration
/usr/include/qt3/qtextstream.h:196: error: 'QTextStream' does not name a type
/usr/include/qt3/qtextstream.h:198: error: invalid function declaration
/usr/include/qt3/qtextstream.h:214: error: invalid function declaration
/usr/include/qt3/qtextstream.h:234: error: 'QTextStream' has not been declared
/usr/include/qt3/qtextstream.h:234: error: non-member function 'QIODevice* device()' cannot have cv-qualifier
/usr/include/qt3/qtextstream.h: In function 'QIODevice* device()':
/usr/include/qt3/qtextstream.h:235: error: 'dev' was not declared in this scope
/usr/include/qt3/qtextstream.h: At global scope:
/usr/include/qt3/qtextstream.h:237: error: 'QTextStream' has not been declared
/usr/include/qt3/qtextstream.h:237: error: non-member function 'bool atEnd()' cannot have cv-qualifier
/usr/include/qt3/qtextstream.h: In function 'bool atEnd()':
/usr/include/qt3/qtextstream.h:238: error: 'dev' was not declared in this scope
/usr/include/qt3/qtextstream.h: At global scope:
/usr/include/qt3/qtextstream.h:240: error: 'QTextStream' has not been declared
/usr/include/qt3/qtextstream.h:240: error: non-member function 'bool eof()' cannot have cv-qualifier
/usr/include/qt3/qtextstream.h:243: error: 'QTextStream' has not been declared
/usr/include/qt3/qtextstream.h:243: error: non-member function 'int flags()' cannot have cv-qualifier
..and the list of errors goes on. My assumption is that the Qt3 headers conflicts with the Qt4 headers and prevent my application from being compiled. However, this seems wrong to me. Shouldn't I be able to build an application that is built upon Qt4 but which can be used with KDE 3.x? Will I have to wait for some KDE4 pre-betas if I want to intergrate my Qt4 app with KDE?

I am not too familiar with how Qt3 differs from Qt4 but maybe it is enough to make it impossible to make a Qt4 app for KDE 3. If someone can just confirm this so I can go back to Qt3 and wait for Qt4 apps until KDE4 is coming somewhere (although if I would prefer it if someone could tell me "do this" and I would be able to keep using Qt4 ;).

Thanks.

Last edited by Ephracis; 01-16-2006 at 05:04 AM.
 
Old 01-16-2006, 08:37 AM   #5
Ephracis
Senior Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Ubuntu, Debian
Posts: 1,109

Original Poster
Rep: Reputation: 50
When I got home I did a little googling and found this: http://www.nabble.com/KDE3-and-Qt4-t690737.html
It seems that I will have to do a Qt3 app instead of using Qt4 for now.

But, I might as well ask here, since I cannot find it in the manual: is there any shortcuts with the editing of the Makefile (where I had to add some includes)? Can I make qmake add some directories to the INCPATH? As it is now I have to manually edit the Makefile after every time I run qmake.
 
Old 01-16-2006, 10:28 AM   #6
Ephracis
Senior Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Ubuntu, Debian
Posts: 1,109

Original Poster
Rep: Reputation: 50
It seems that KConfig did not work. I get a segfault using the same code I got, including kconfig.h and kglobal.h, and adding -lkdecore to the linker. The only guide I could find for kconfig was the KConfig XT guide which seemed a little too complicated and assumed that I had worked with KConfig earlier.

Is there any good guide out there that introduces kconfig, for people like me whom have never used kconfig before? The code I got earlier in this thread made kconfig look like a play, easy to store and easy to retrieve. However, the KConfig XT guide made me believe that it is far from that easy, I will have to create a xml file, a .kcfgc file and convert it into c++ code, etc.

I like KDE, but seriously, the documentation for developers is far from satisfying. I don't know anything about how to use kparts or how to use kconfig, and I can't find any documentation on it either. Maybe I should stop doing this and program for Gnome instead? Or Windows (say what you want about it, but at least you have some good reading there).

I'm getting frustrated, please help me.

Thanks.
 
Old 01-16-2006, 02:58 PM   #7
foo_bar_foo
Senior Member
 
Registered: Jun 2004
Posts: 2,553

Rep: Reputation: 53
sorry i didn't know it was qt only app i have never tried to do these things without using
KApplication
as the application object so that might be the solution
 
Old 01-16-2006, 04:16 PM   #8
Ephracis
Senior Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Ubuntu, Debian
Posts: 1,109

Original Poster
Rep: Reputation: 50
Quote:
Originally Posted by foo_bar_foo
sorry i didn't know it was qt only app i have never tried to do these things without using
KApplication
as the application object so that might be the solution
I will look into that KApplication, it sounds like something I could need. :)
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Method Not Allowed: The requested method POST is not allowed for the URL /writedhcp.p WiWa Linux - Networking 15 01-06-2011 01:20 PM
store aumix volume settings props666999 Slackware 2 06-15-2005 06:28 AM
KDE undo "store window settings" uselpa Slackware 0 01-01-2005 05:47 AM
Setterm -powerdown 2 -store not saving settings after reboot kragbax Linux - Newbie 1 12-22-2004 10:11 PM
where does mandrake (9.1) store X config settings? jacksonscottsly Linux - Newbie 3 11-27-2003 10:14 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:00 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration