diff --git a/src/kdeclarative/qmlobjectsharedengine.cpp b/src/kdeclarative/qmlobjectsharedengine.cpp index c458333..73add8a 100644 --- a/src/kdeclarative/qmlobjectsharedengine.cpp +++ b/src/kdeclarative/qmlobjectsharedengine.cpp @@ -1,81 +1,81 @@ /* * Copyright 2015 Marco Martin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "qmlobjectsharedengine.h" #include #include #include #include namespace KDeclarative { class QmlObjectSharedEnginePrivate { public: QmlObjectSharedEnginePrivate() { //ensure the engine is present, then ref it engine(); engineRef = s_engine; } ~QmlObjectSharedEnginePrivate() { //when the only remaining are out two refs, reset the pointers, causing deletion //when the refcount is 2, we are sure that the only refs are s_engine and our copy //of engineRef if (engineRef.use_count() == 2) { s_engine.reset(); } } static QQmlEngine *engine() { if (!s_engine) { s_engine = std::make_shared(); KDeclarative::setupEngine(s_engine.get()); } return s_engine.get(); } //used to delete it std::shared_ptr engineRef; static std::shared_ptr s_engine; }; std::shared_ptr QmlObjectSharedEnginePrivate::s_engine = std::shared_ptr(); QmlObjectSharedEngine::QmlObjectSharedEngine(QObject *parent) : QmlObject(QmlObjectSharedEnginePrivate::engine(), new QQmlContext(QmlObjectSharedEnginePrivate::engine()), this /*don't call setupEngine*/, parent), d(new QmlObjectSharedEnginePrivate()) { + rootContext()->setParent(this); } QmlObjectSharedEngine::~QmlObjectSharedEngine() { - rootContext()->deleteLater(); } } #include "moc_qmlobjectsharedengine.cpp"