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

avoid error on stdout using KConfig from shared lib

Tags: None
(comma "," separated)
sommerluk
Registered Member
Posts
12
Karma
0
OS
Hello.

I want to use KConfig in a shared library because I want to make use of KDE's KIOSK system, default values etc:

Code: Select all
KConfig kde_cf("kioslaverc", KConfig::NoGlobals);
KConfigGroup kde_settings(&kde_cf, "Proxy Settings");


The problem is that instantiating KConfig produces an error on stdout (or stderr?):

QApplication::qAppName: Please instantiate the QApplication object first


The library may not produce any output. So how can I avoid this output? Some ideas I had didn't work:

    Instantiate QApplication is not possible because this would interfer with a possibly created QApplication/KApplication instance that was created by the application that uses the library.
    Change the Qt Message handler is also a bad idea because qInstallMsgHandler isn't thread-save and furthermore the change of the message handler could suppress error messages of a thread of the application that uses the library.

So what other possibilities do I have?


Lukas Sommer
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
You need to ensure that any / all users of your shared library use KApplication / QApplication.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
sommerluk
Registered Member
Posts
12
Karma
0
OS
Well, that's exactly what I can not make sure. Some of them will use KApplication/QApplication, some of them no (GTK applications...).


Lukas Sommer
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
Presence of a QApplication or KApplication instance is required to use KConfig. You will likely need to use GNOME's infrastructure if it has one in the case of it being used in a Gtk application.

You can do this by checking the validity of the qApp pointer.

Code: Select all
if( qApp ) {
 // Use KConfig
} else {
 // Use something else
}


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
sommerluk
Registered Member
Posts
12
Karma
0
OS
Okay. Thank you.


Lukas Sommer


Bookmarks



Who is online

Registered users: abc72656, Bing [Bot], daret, Google [Bot], Sogou [Bot], Yahoo [Bot]