Version: (using KDE KDE 3.1) Installed from: FreeBSD Ports Compiler: gcc 3.2.2 OS: FreeBSD I'm developing a program that uses libtaskmanager from kicker for task control and switching. (It's a Pie-Menu replacement for the current Alt+Tab switcher, but that's irrelevant.) When linking against libtaskmanager, whether or not I actually use it, I consistently get an error about creating a QPaintDevice without a QApplication. This happens before my main() routine is even executed, and appears to be a result of something libtaskmanager is doing on load. Glancing over the code, I noticed (on line 49 of kdebase/kicker/taskmanager/taskmanager.cpp) that a single instance of KWinModule was being allocated for the functions in the file. Because this is being allocated globally, it's created on loading the library, before a client program can allocate a QApplication. (There are ways around this, but they're more work than they're worth.) The fix is simple: initialize the KWinModule pointer to NULL and use lazy creation in the TaskManager constructor. This operates on one assumption, however: namely, that Task objects will never be allocated without an accompanying TaskManager. The Task object code makes this same assumption, however, by not checking the TaskManager *parent for NULL, so I feel it's safe. With this patch, arbitrary code is able to easily link to and use libtaskmanager to retrieve information about the windowed tasks on a KDE system. (Though taskmanager.h has to be manually copied out of kdebase to make it useful -- why is this not installed? Time for another bug!) Patch attached.
Created attachment 1218 [details] Patch to kdebase/kicker/taskmanager/taskmanager.cpp Adds lazy creation of kwin_module object. Prevents it from being allocated before linking apps can do their initialization.
Thanks for the patch; looks good, please apply and update the comment above the declaration with the reasoning for the new behavior.
I've attached a new patch that revises the comments in the area to reflect the new behavior.
Created attachment 1219 [details] Revision of earlier patch, now with comments.
Subject: kdebase/kicker/taskmanager CVS commit by firebaugh: Lazily allocate the kwin module. CCMAIL: 56251-done@bugs.kde.org M +5 -2 taskmanager.cpp 1.59 --- kdebase/kicker/taskmanager/taskmanager.cpp #1.58:1.59 @@ -47,9 +47,12 @@ template class QPtrList<Task>; // So, we'll leak a little memory, but it's better than crashing. // The real problem is that KWinModule should be a singleton. -KWinModule* kwin_module = new KWinModule(); +KWinModule* kwin_module = NULL; TaskManager::TaskManager(QObject *parent, const char *name) : QObject(parent, name), _active(0), _startup_info( NULL ) { + if ( kwin_module == NULL ) + kwin_module = new KWinModule(); + KGlobal::locale()->insertCatalogue("libtaskmanager"); connect(kwin_module, SIGNAL(windowAdded(WId)), SLOT(windowAdded(WId)));
*** Bug 57230 has been marked as a duplicate of this bug. ***