From a3318e33db2aeac570e910acf99cc1d4f3b8ed45 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Tue, 2 Feb 2021 16:16:39 +0100 Subject: [PATCH] Make Class View interactive again After you load the project, and after "Parsing C/C++ Files" has finished, if you open the Class View and start typing in cpp editor, a warning appears: "QObject::killTimer: Timers cannot be stopped from another thread" and changes to source files, like adding a new method or renaming it, are not reflected anymore in Class View. Short: A fix is to give timer a parent in order to move it properly into another thread. Long: Just after creating a Parser object we move it into another thread by calling moveToThread(), inside constructor of Manager in classviewmanager.cpp. All the children of the moved object are moved together into the target thread. Original intention of the timer object inside Parser was that it should live in the same thread as its parent Parser object. In meantime, after some refactoring, that's not the case anymore and the timer is orphaned (parentless in terms of QObject hierarchy). It means it's not moved together with the parent Parser anymore, while still being a member field of the Parser. This is reflected in a warning message and class view doesn't react to the changes in edited document anymore. Amends 87b3ea9af400aeddd1e4918badb4ae255d2a7cd3 Change-Id: I9cca7556d5b77aa31ce7b4ab426f84a478488a84 Reviewed-by: Christian Kandeler --- src/plugins/classview/classviewparser.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/plugins/classview/classviewparser.cpp b/src/plugins/classview/classviewparser.cpp index 61e0f5a5af0..0755da374b1 100644 --- a/src/plugins/classview/classviewparser.cpp +++ b/src/plugins/classview/classviewparser.cpp @@ -94,6 +94,9 @@ namespace Internal { class ParserPrivate { public: + // Keep timer as a child of Parser in order to move it together with its parent + // into another thread. + ParserPrivate(QObject *parent) : timer(parent) {} using CitDocumentList = QHash::const_iterator; //! Get document from documentList @@ -160,7 +163,7 @@ CPlusPlus::Document::Ptr ParserPrivate::document(const QString &fileName) const Parser::Parser(QObject *parent) : QObject(parent), - d(new ParserPrivate()) + d(new ParserPrivate(this)) { d->timer.setSingleShot(true);