From 58d281d0b9f82d797b3b14fa8d0ffb321c3801aa Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Wed, 28 Mar 2012 14:11:10 +0200 Subject: [PATCH] fix connect to destroyed, should solve crashes --- .../plasmacomponents/fullscreenwindow.cpp | 6 ++++- .../plasmacomponentsplugin.cpp | 23 +++++++------------ .../plasmacomponents/plasmacomponentsplugin.h | 2 +- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/declarativeimports/plasmacomponents/fullscreenwindow.cpp b/declarativeimports/plasmacomponents/fullscreenwindow.cpp index 062b21380..35d23aae5 100644 --- a/declarativeimports/plasmacomponents/fullscreenwindow.cpp +++ b/declarativeimports/plasmacomponents/fullscreenwindow.cpp @@ -147,7 +147,11 @@ void FullScreenWindow::init(const QString &componentName) } - QDeclarativeEngine *engine = EngineBookKeeping::self()->engineFor(this); + QDeclarativeEngine *engine = EngineBookKeeping::self()->engine(); + if (!engine) { + kWarning() << "Warning, no QDeclarativeEngines available anymore, should never happen"; + Q_ASSERT(0); + } QDeclarativeComponent *component = new QDeclarativeComponent(engine, filePath, this); QDeclarativeContext *creationContext = component->creationContext(); diff --git a/declarativeimports/plasmacomponents/plasmacomponentsplugin.cpp b/declarativeimports/plasmacomponents/plasmacomponentsplugin.cpp index bfc98a7f3..a1d548bf2 100644 --- a/declarativeimports/plasmacomponents/plasmacomponentsplugin.cpp +++ b/declarativeimports/plasmacomponents/plasmacomponentsplugin.cpp @@ -54,28 +54,21 @@ EngineBookKeeping *EngineBookKeeping::self() return &privateBKSelf->self; } -QDeclarativeEngine *EngineBookKeeping::engineFor(QObject *item) const +QDeclarativeEngine *EngineBookKeeping::engine() const { //for components creation, any engine will do, as long is valid - return m_engines.values().first(); - /* - foreach (QDeclarativeEngine *engine, m_engines) { - QObject *root = engine->rootContext()->contextObject(); - QObject *candidate = item; - - while (candidate) { - if (candidate == root) { - return engine; - } - candidate = candidate->parent(); - } + if (m_engines.isEmpty()) { + kWarning() << "No engines found, this should never happen"; + return 0; + } else { + return m_engines.values().first(); } - return 0;*/ } void EngineBookKeeping::insertEngine(QDeclarativeEngine *engine) { - connect(engine, SIGNAL(destroyed(QObject *)), this, SLOT(engineDestroyed(QObject *deleted))); + connect(engine, SIGNAL(destroyed(QObject *)), + this, SLOT(engineDestroyed(QObject *))); m_engines.insert(engine); } diff --git a/declarativeimports/plasmacomponents/plasmacomponentsplugin.h b/declarativeimports/plasmacomponents/plasmacomponentsplugin.h index e4226dc56..7384060c7 100644 --- a/declarativeimports/plasmacomponents/plasmacomponentsplugin.h +++ b/declarativeimports/plasmacomponents/plasmacomponentsplugin.h @@ -36,7 +36,7 @@ public: static EngineBookKeeping *self(); void insertEngine(QDeclarativeEngine *engine); - QDeclarativeEngine *engineFor(QObject *item) const; + QDeclarativeEngine *engine() const; private Q_SLOTS: void engineDestroyed(QObject *deleted);