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

undesired console output with KConfig

Tags: None
(comma "," separated)
User avatar
urwald
Registered Member
Posts
30
Karma
0
OS
Hello.

I want to make use of KConfig in a shared library to provide full-featured (kiosk, cascading various config files...) config file suport. The problem is that the constructor of KConfig seems to make directly or indirectly use of qAppName(). I get the following error message on the console:

QApplication::qAppName: Please instantiate the QApplication object first

The library doesn't accept additional output. And I can't instanciate a QApplication or KApplication object because it is a library. (Linking a Qt or KDE program against such a library will crash because there may be only one QApplication object at runtime.)

Is there a possibility to
1.) supress the console output
or
2.) work around this console output?


urwald, proud to be a member of KDE forums since 2008-Oct.
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
You need to alter the testing application to create a Q/KApplication instance. It is not the responsibility of the libraries to create them, but they in virtually all cases require them.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
User avatar
urwald
Registered Member
Posts
30
Karma
0
OS
bcooksley wrote:You need to alter the testing application to create a Q/KApplication instance.


It's not an application, it's a library. Because it's a library, I can't create a Q/KApplication instance because it would interfer with the instance that is created by a program that uses the library and the application that links to the library would crash.

So I need another way: Either suppress the output or some sort of workaround. By I have no idea...


urwald, proud to be a member of KDE forums since 2008-Oct.
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
You shouldn't be running the library directly. You should have a testing application to use it, and that should create a KApplication instance.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
User avatar
urwald
Registered Member
Posts
30
Karma
0
OS
Hm, you don't understand me.

I want to write a lib. The lib has to use KConfig.

- When I create an instance of Q/KApplication in the lib, it will interfer with the instance that I create in the program that uses the lib.

- When I don't create an instance of Q/KApplication in the lib, I will the the error message "QApplication::qAppName: Please instantiate the QApplication object first" independently if the application creates Q/KApplication or not.

So, again, my question:

Is there a possibility to
1.) supress the console output
or
2.) work around this console output?


urwald, proud to be a member of KDE forums since 2008-Oct.
User avatar
urwald
Registered Member
Posts
30
Karma
0
OS
Finally, I've found a way to implement it differently. So this is SOLVED.


urwald, proud to be a member of KDE forums since 2008-Oct.
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
Ok..

That error should not have occurred, possibly because your code was being called before kApp.exec() was called.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
User avatar
urwald
Registered Member
Posts
30
Karma
0
OS
Hm, I have found (and that works fine) that all of Qt's messages by modifying temporally the internal component for message output (see qInstallMsgHandler for details). That's a nice solution.


urwald, proud to be a member of KDE forums since 2008-Oct.


Bookmarks



Who is online

Registered users: Bing [Bot], daret, Google [Bot], sandyvee, Sogou [Bot]