Help me understand Qt.quit()

• 18 Juill. 2018 - 03:31

The attached plugin code has the following onRun block:

    onRun: {
        console.log("flag 1");
        if (true) {
            console.log("flag 2");
            console.log("flag 3");
        console.log("flag 4");
            function(note) {
                note.color = "orange";
        console.log("flag 5");

As I would expect, flags 1 and 2 print, and flags 3-5 don't. But I don't understand why applyToNotesInSelection is executed, coloring any selected notes orange.

Could someone explain what's happening here?

Fichier attaché Taille
quitTest.qml 2.97 KB


I'll make an attempt to clarify. The main reason for this behavior is that a QML plugin is run on top of the Qt Event(loop) system.

See and the related signal description. When you call Qt.quit() you're not actually quitting the execution of your script. You are sending out a signal saying that you would like to stop executing the script and the QmlEngine running you should stop you.
So you place that signal (event) onto the eventlist to be processed by the QmlEngine, but you may still be further executing in your script.

At a later point in time, control is switched away from your script and to the next thread; eventually the QmlEngine will be swapped in.
It is only now that it can start processing its Eventlist; and only once it reaches the quit-event you've sent out in that list, will it actually terminate your script; thus preventing further execution.

Do you still have an unanswered question? Please log in first to post your question.