[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-core-devel
Subject: [patch] [update] ktexteditor avoid multiple deletion;
From: Jarosław Staniek <js () iidea ! pl>
Date: 2008-04-11 23:13:13
Message-ID: 47FFF089.7070002 () iidea ! pl
[Download RAW message or body]
for review; (update for [patch] KTextEditorFactoryList: make qAddPostRoutine
play well with K_GLOBAL_STATIC [2008-04-11 15:16])
Example: KWrite uses KTextEditor::EditorChooser::editor(), what in turn calls
KTextEditor::editor("katepart") for each new editor window, always with the
same part name.
Solution: Use QSet (KTextEditorFactorySet) instead of QList to avoid multiple
deletion of the same factory object.
--
regards / pozdrawiam, Jaroslaw Staniek
Sponsored by OpenOffice Polska (http://www.openoffice.com.pl/en) to work on
Kexi & KOffice (http://www.kexi.pl/en, http://www.koffice.org/kexi)
KDE Libraries for MS Windows (http://windows.kde.org)
["ktexteditor2.patch" (text/plain)]
Index: interfaces/ktexteditor/ktexteditor.cpp
===================================================================
--- interfaces/ktexteditor/ktexteditor.cpp (wersja 795732)
+++ interfaces/ktexteditor/ktexteditor.cpp (kopia robocza)
@@ -188,17 +188,21 @@
return KService::createInstance<KTextEditor::Plugin>(service, parent);
}
-struct KTextEditorFactoryList : public QList<KPluginFactory*>
+struct KTextEditorFactorySet : public QSet<KPluginFactory*>
{
- KTextEditorFactoryList() {}
- ~KTextEditorFactoryList() { qDeleteAll(*this); }
+ KTextEditorFactorySet();
+ ~KTextEditorFactorySet();
};
-K_GLOBAL_STATIC(KTextEditorFactoryList, s_factoryList)
-static void cleanupKTextEditorFactoryList()
-{
- qDeleteAll(*s_factoryList);
- s_factoryList->clear();
+K_GLOBAL_STATIC(KTextEditorFactorySet, s_factories)
+KTextEditorFactorySet::KTextEditorFactorySet() {
+ // K_GLOBAL_STATIC is cleaned up *after* Q(Core)Application is gone
+ // but we have to cleanup before -> use qAddPostRoutine
+ qAddPostRoutine(s_factories.destroy);
}
+KTextEditorFactorySet::~KTextEditorFactorySet() {
+ qRemovePostRoutine(s_factories.destroy); // post routine is installed!
+ qDeleteAll(*this);
+}
Editor *KTextEditor::editor(const char *libname)
{
@@ -211,11 +215,7 @@
return 0;
}
- // K_GLOBAL_STATIC is cleaned up *after* Q(Core)Application is gone
- // but we have to cleanup before -> use qAddPostRoutine
- if(s_factoryList->count() == 0)
- qAddPostRoutine(cleanupKTextEditorFactoryList);
- s_factoryList->append(fact);
+ s_factories->insert(fact);
return ef->editor();
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic