Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Qt.callLater() and invalid context

Qt.callLater() and invalid context

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 244 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kai Nickel
    wrote on last edited by
    #1

    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?
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      1. Intuitively, I would say you are using it correctly
      2. Likely an unintended consequence
      3. 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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved