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 87b3ea9af4

Change-Id: I9cca7556d5b77aa31ce7b4ab426f84a478488a84
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Jarek Kobus
2021-02-02 16:16:39 +01:00
parent 1ca15fe2e9
commit a3318e33db

View File

@@ -94,6 +94,9 @@ namespace Internal {
class ParserPrivate class ParserPrivate
{ {
public: 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<QString, CPlusPlus::Document::Ptr>::const_iterator; using CitDocumentList = QHash<QString, CPlusPlus::Document::Ptr>::const_iterator;
//! Get document from documentList //! Get document from documentList
@@ -160,7 +163,7 @@ CPlusPlus::Document::Ptr ParserPrivate::document(const QString &fileName) const
Parser::Parser(QObject *parent) Parser::Parser(QObject *parent)
: QObject(parent), : QObject(parent),
d(new ParserPrivate()) d(new ParserPrivate(this))
{ {
d->timer.setSingleShot(true); d->timer.setSingleShot(true);