Qt.callLater() and invalid context
-
With Qt 6.10 I get an error when using Qt.callLater() in an object that gets destroyed before the delayed call can actually be executed.
Example:
import QtQuick Window { id: root Component { id: testComp QtObject { function hello(): void { console.log("Hello"); } Component.onCompleted: { Qt.callLater(() => hello()); } } } Loader { id: loader active: true sourceComponent: testComp } Component.onCompleted: { loader.active = false; } }"Hello" is not printed (which is fine), but then this error comes up:
QQmlVMEMetaObject: Internal error - attempted to evaluate a function in an invalid context qrc:/IssueTest/Main.qml:13: TypeError: Property 'hello' of object QObject_QML_1(0xe41e9a0) is not a function (exception occurred during delayed function evaluation)My questions are:
- How to use Qt.callLater() safely?
- Why did the behavior change? (there was no error in previous Qt versions)
- Do you consider this a bug?
-
Hi,
- Intuitively, I would say you are using it correctly
- Likely an unintended consequence
- I would think so
You should check the bug report system to see if this is something known. If not please open a new ticket containing a complete minimal buildable example showing this.