Component.onCompleted doesn't seem to be called

• Sep 30, 2020 - 19:48

Here's a minimal version of the code:

import QtQuick 2.0
import MuseScore 3.0

MuseScore {
      menuPath: "Plugins.pluginName"
      description: "Description goes here"
      version: "1.0"
      onRun: {
            console.log("hello world")
            Qt.quit()
            }

      Component.onCompleted: console.log("This will not be printed")
      }

You'll see that the last line doesn't show in the log.

Am i missing something obvious, or is this a bug?


Comments

You don't see the log output from onCompleted because the framework creates the plugin first and only then attaches the slots that handle the call to console.log

import QtQuick 2.0
import MuseScore 3.0
 
MuseScore {
      menuPath: "Plugins.pluginName"
      description: "Description goes here"
      version: "1.0"
      requiresScore: false
      onRun: {
            console.log("version: " + version);
            Qt.quit();
            }
 
      Component.onCompleted: function() {
            //version = 2; // uncomment this line
            console.log("This will not be printed");
            }
      }

The following plugin clearly shows that completed is run, as witnessed when uncommenting the marked line.
Also remember that "completed" in this case will mean whenever MuseScore loads the plugin (so at program startup for example); not whenever a user invokes it (that's what onRun is for).

It works for QML constructs as well; see for example https://github.com/jeetee/MuseScore_Parsons_Code_Exporter/blob/master/P… where it is used to hide the File dialog upon creation so it only shows after a user presses the browse button.

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