qmljstools::LocatorData: improve safety

* check that we create LocatorData in the same thread as the
  ModelManagerInterface
* pass this as connect context, to ensure signal disconnect

Change-Id: I5e51af90c521fd8c83a6cfe2d105832f5a02a04f
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
Fawzi Mohamed
2021-06-24 17:56:13 +02:00
parent f42b68f4af
commit 584f0476ec

View File

@@ -43,6 +43,7 @@ using namespace QmlJS::AST;
LocatorData::LocatorData() LocatorData::LocatorData()
{ {
ModelManagerInterface *manager = ModelManagerInterface::instance(); ModelManagerInterface *manager = ModelManagerInterface::instance();
Q_ASSERT(thread() == manager->thread()); // we do not protect accesses below
// Force the updating of source file when updating a project (they could be cached, in such // Force the updating of source file when updating a project (they could be cached, in such
// case LocatorData::onDocumentUpdated will not be called. // case LocatorData::onDocumentUpdated will not be called.
@@ -61,8 +62,10 @@ LocatorData::LocatorData()
ProjectExplorer::SessionManager *session = ProjectExplorer::SessionManager::instance(); ProjectExplorer::SessionManager *session = ProjectExplorer::SessionManager::instance();
if (session) if (session)
connect(session, &ProjectExplorer::SessionManager::projectRemoved, connect(session,
[this] (ProjectExplorer::Project*) { m_entries.clear(); }); &ProjectExplorer::SessionManager::projectRemoved,
this,
[this](ProjectExplorer::Project *) { m_entries.clear(); });
} }
LocatorData::~LocatorData() = default; LocatorData::~LocatorData() = default;