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

Using KConfigDialog

Tags: None
(comma "," separated)
User avatar
lin-unix
Registered Member
Posts
34
Karma
0
OS

Using KConfigDialog

Mon Nov 22, 2010 10:36 pm
I'm trying to create a KConfigDialog for a program I am making but I have no idea how KConfigSkeleton works. I've spent 2 days reading the KDE API on KConfig and things related to it, but no progress has been made. Can someone give me an example of how I can setup KConfigSkeleton so I can pass it into KConfigDialog()?

I believe a KConfigDialog is created with:
Code: Select all
KConfigDialog *configDialog = new KConfigDialog(QWidget *parent, const QString &name, KConfigSkeleton *config)


But from here I get stuck at KConfigSkeleton.
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS

Re: Using KConfigDialog

Tue Nov 23, 2010 2:26 am
First, you need to use KConfigXT. You can then call ClassName::self() to get a KConfigSkeleton, where ClassName comes from your *.kcfg file. See techbase.kde.org for a tutorial and System Settings in KDE SVN for an example.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
User avatar
lin-unix
Registered Member
Posts
34
Karma
0
OS

Re: Using KConfigDialog

Mon Nov 29, 2010 7:14 pm
Thanks for pointing me in the right direction.

I've set up my kcfg and kcfgc files and added the two lines into my CMakeLists.txt, but I can't get my program to compile. The compiler can't find my the new .cpp and .h file is supposed to be created. It's not created in fact.

Settings.kcfgc:
Code: Select all
# Code generation options for kconfig_compiler
File=Settings.kcfg
ClassName=KReminderSettings
Singleton=true
Mutators=true


Settings.kcfg:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
                          http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
  <kcfgfile name="KReminderrc"/>
  <group name="wSize">
      <entry name="Width" type="Int">
          <label>Width of the main window.</label>
          <default>50</default>
      </entry>
  </group>
</kcfg>
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS

Re: Using KConfigDialog

Tue Nov 30, 2010 2:13 am
Can you please post your CMakeLists.txt?

You should have a statement similar to this in it:
Code: Select all
KDE4_ADD_KCFG_FILES( systemsettings_SRCS BaseConfig.kcfgc )


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
User avatar
lin-unix
Registered Member
Posts
34
Karma
0
OS

Re: Using KConfigDialog

Tue Nov 30, 2010 4:57 pm
Code: Select all
project(KReminder)
cmake_minimum_required(VERSION 2.6)
find_package(KDE4 REQUIRED)

include(KDE4Defaults)
include_directories(${CMAKE_CURRENT_BINARY_DIR} ${KDE4_INCLUDES})

set(KReminder_SRCS KReminder.cpp KReminderConfigure.cpp main.cpp)
kde4_add_kcfg_files(KReminder_SRCS Settings.kcfgc)
kde4_add_executable(KReminder ${KReminder_SRCS})
target_link_libraries(KReminder ${KDE4_KDEUI_LIBS})

install(FILES Settings.kcfg DESTINATION ${KCFG_INSTALL_DIR})
install(TARGETS KReminder DESTINATION ${BIN_INSTALL_DIR})
install(FILES KReminderui.rc DESTINATION ${DATA_INSTALL_DIR}/KReminder)


Maybe the location of kde4_add_kcfg_files is wrong.
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS

Re: Using KConfigDialog

Wed Dec 01, 2010 6:12 am
Can you send me a copy of the source so I can experiment? You may need to re-run CMake in the build directory in case it missed your changes somehow.

Also, try adding ${CMAKE_CURRENT_SOURCE_DIR} to your include directories, and the following CMake statement:
Code: Select all
ADD_DEFINITIONS(${QT_DEFINITIONS} ${KDE4_DEFINITIONS})


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
User avatar
lin-unix
Registered Member
Posts
34
Karma
0
OS

Re: Using KConfigDialog

Wed Dec 01, 2010 4:46 pm
Hmm, anyway to attach the code? If not I'll give you all the relevant code (I can give it all but I have libraries that do other things not relevant to this).

Source code:
Code: Select all
#include "KReminderConfigure.h"
#include "KReminderSettings.h"

#include <KConfigDialog>

KReminderConfigure::KReminderConfigure(QWidget *parent)
{
    setupWindow(parent);
}

void KReminderConfigure::setupWindow(QWidget *parent)
{
    KConfigDialog *configWindow = new KConfigDialog(parent, "configWindow", KReminderSettings::self());
}

KReminderConfigure::~KReminderConfigure()
{}


Header file:
Code: Select all
#ifndef KREMINDERCONFIGURE_H
#define KREMINDERCONFIGURE_H

#include <QWidget>

#include <KConfigSkeleton>

class KReminderConfigure
{
    public:
        KReminderConfigure(QWidget *parent);
        virtual ~KReminderConfigure();

    private:
        void setupWindow(QWidget *parent);
};

#endif // KREMINDERCONFIGURE_H
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS

Re: Using KConfigDialog

Fri Dec 03, 2010 1:36 am
A tarball of your project should be enough. I can't see anything wrong with those two files you have posted though. You can't upload files to the forum however, I'd recommend sending them to my email address, or posting it on a public site where I can download it from. My email address is (my forum username here)@kde.org.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
B4700011
Registered Member
Posts
16
Karma
0

Re: Using KConfigDialog

Thu Dec 16, 2010 9:23 pm
lin-unix wrote:I've set up my kcfg and kcfgc files and added the two lines into my CMakeLists.txt, but I can't get my program to compile. The compiler can't find my the new .cpp and .h file is supposed to be created. It's not created in fact.


In your CMakeLists.txt, below your kde4_add_kfcg line, try adding this:
Code: Select all
message("KReminder_SRCS = ${KReminder_SRCS}")

then run cmake and you should see a line saying "KReminder_SRCS..." scroll by, it will show you the names of the class files which kconfig_compiler has supposedly generated. Check if they exist (ln -l ....) I expect in your case they will be named Settings.{h,cpp} -- make sure they don't conflict with anything else in your code.

Finally, wherever you access the configuration, you sould have an
Code: Select all
#include "Settings.h"

or similar line.

If still no luck, try running xmllint in your .kcfg file to make sure it's well-formed.
Code: Select all
xmllint --noout Settings.kcfg


The last thing to try is run kconfig_compiler by hand on your input files, see what comes out:
Code: Select all
kconfig_compiler /path/to/Settings.kcfg /path/to/Settings.kcfgc

then
Code: Select all
ls -lrt

to see what has been generated, if anything.

Hope this helps a bit.
User avatar
lin-unix
Registered Member
Posts
34
Karma
0
OS

Re: Using KConfigDialog

Wed Dec 22, 2010 4:44 am
Thanks for your help everyone.

I'm currently digging up my code after a clean install of my OS.
Apparently, a milestone of openSUSE 11.4 and KDE 4.6 Beta2 are not a good combination, who would have thought? ;)

So I'll get back to you about my results on KConfig.


Bookmarks



Who is online

Registered users: Bing [Bot], claydoh, Google [Bot], markhm, rblackwell, sethaaaa, Sogou [Bot], Yahoo [Bot]