Help me understand Qt.quit()
The attached plugin code has the following onRun block:
onRun: { console.log("flag 1"); if (true) { console.log("flag 2"); Qt.quit(); console.log("flag 3"); } console.log("flag 4"); applyToNotesInSelection( function(note) { note.color = "orange"; } ); console.log("flag 5"); Qt.quit(); }
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 |
Commentaires
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 http://doc.qt.io/qt-5/qml-qtqml-qt.html#quit-method 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.
En réponse à I'll make an attempt to… par jeetee
Thank you jeetee! That's very helpful and gives me an idea where to look for more details. And I can set a boolean variable to prevent note-processing if there are errors, now that I understand why
Qt.quit()
isn't doing it for me.En réponse à I'll make an attempt to… par jeetee
https://musescore.github.io/MuseScore_PluginAPI_Docs/plugins/html/ is still documenting
Qt.quit();
as required to exit the plugin.Do I understand it correctly that…
onRun
method to terminateimport QtQuick.Window 2.2
and callpluginId.parent.Window.window.close();
…?
En réponse à https://musescore.github.io… par mirabilos
… and when I need to terminate early (in a normal plugin) I can just do
throw new Error("message");
(or return from onRun)?Do I need to roll back the
curScore.startCmd();
for that, and if so, how?En réponse à … and when I need to… par mirabilos
> still documenting
the doxygen doc is computer gen and not well maintained (by dmitrio95)
jot down your valuable discovery and read other users' here
https://musescore.org/en/handbook/developers-handbook/plugins-3x
> some info about quit
https://musescore.org/en/handbook/developers-handbook/plugins-3x#apibas…
En réponse à > still documenting the… par msfp
But that documentation is the first thing people look at when writing plugins…
En réponse à But that documentation is… par mirabilos
Yea that's unfortunate. seems dmitrio95's not active on plugin api dev anymore and I have no idea who the doxygen website admin is.
En réponse à Yea that's unfortunate… par msfp
It’s generated from comments in the C++ source code. In Debian, that’s even available offline…
En réponse à It’s generated from comments… par mirabilos
Yes, but it still needs to be done and published
En réponse à But that documentation is… par mirabilos
See #319822: Plugin documentation has not been updated for 3.6
En réponse à https://musescore.github.io… par mirabilos
That documentation is outdated, stems from 3.5 (but that was wrong even there)