fix connect to destroyed, should solve crashes

This commit is contained in:
Marco Martin 2012-03-28 14:11:10 +02:00
parent 5b452bfb9a
commit 58d281d0b9
3 changed files with 14 additions and 17 deletions

View File

@ -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();

View File

@ -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
if (m_engines.isEmpty()) {
kWarning() << "No engines found, this should never happen";
return 0;
} else {
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();
}
}
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);
}

View File

@ -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);