MessageDialog code stops plugin from loading

• Mar 18, 2025 - 02:27

I am using Windows 8.1 (6.3), Arch.: x86_64, MuseScore version (64-bit): 3.6.2.548021803, revision: 3224f34

This program uses Qt version 5.9.9.

I am trying to output some data after my plugin runs.
But as soon as I add the following code, the plugin no longer reloads.
What am I missing?

var debugDialog = MessageDialog {
title: qsTr("NOBREAK Plugin Results")
text: qsTr(messageText)
standardButtons: StandardButton.Ok
onAccepted: Qt.quit // Exit after the user clicks OK.
}
debugDialog.open()

If MessageDialog is not supported, is there another way to output information on the screen?

Here is the rest of the code:

/*
NOBREAK Plugin for MuseScore
Plugin Name: NOBREAK
Description: Searches measures for a staff text equal to "_nb".
If found, the text is hidden, the measure is marked as non-breakable (NOBREAK),
and a MessageDialog lists all affected measure numbers.
Author: [Your Name]
Version: 1.0
*/

import QtQuick 2.0
import QtQuick.Dialogs 1.2
import MuseScore 3.0

MuseScore {
// Marker text to search for
property string markerText: "_nb"

// The name displayed in the plugin menu.
menuPath: "Plugins.NOBREAK"

// Entry point of the plugin.
onRun: {
    if (!curScore) {
        console.log("No score is open.");
        Qt.quit();
        return;
    }

    // Array to store measure numbers with the marker.
    var measuresWithMarker = [];

    // Create a cursor and rewind to start processing by measures.
    var cursor = curScore.newCursor();
    cursor.rewind(Cursor.REWIND_MEASURE);

    // Loop through each measure.
    while (!cursor.eos()) {
        var measure = cursor.measure;
        var foundMarkerInMeasure = false;

        // Iterate over all elements in the measure.
        for (var i = 0; i < measure.elements.length; ++i) {
            var el = measure.elements[i];
            // Check if the element is a StaffText and its text exactly matches the marker.
            if (el && el.type === ElementType.StaffText && el.text === markerText) {
                el.visible = false;   // Hide the marker text.
                foundMarkerInMeasure = true;
            }
        }

        // If we found the marker in the current measure, mark it as NOBREAK.
        if (foundMarkerInMeasure) {
            // Assuming MuseScore supports 'nobreak' property on measures.
            measure.nobreak = true;

            // Record the measure number.
            // (If your MuseScore version uses a different property, adjust accordingly.)
            measuresWithMarker.push(measure.no);
        }

        cursor.nextMeasure();
    }

    // Prepare the message text.
    var messageText = (measuresWithMarker.length > 0) ?
        "Measures with '_nb' marker found:\n" + measuresWithMarker.join(", ") :
        "No measures found";

    // Create a MessageDialog to display the results.
    /*
    var debugDialog = MessageDialog {
        title: qsTr("NOBREAK Plugin Results")
        text: qsTr(messageText)
        standardButtons: StandardButton.Ok
        onAccepted: Qt.quit   // Exit after the user clicks OK.
    }
    debugDialog.open()
    */
}

}


Comments

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