QML calls to functions with Enum parameters ignore the provided parameter

• Jan 12, 2016 - 20:45
S4 - Minor

Discovered on 2.0.2/Win7 and confirmed whilst debugging on current master (3543170)

Consider the following very simple plugin:
import QtQuick 2.0
import MuseScore 1.0

MuseScore {
menuPath: "Plugins.firstSegmentOfType"
onRun: {
console.log('A ChordRest type: ' + Segment.ChordRest);
var f = curScore.firstSegment(Segment.ChordRest);
console.log('First ChordRest of score: ' + f.segmentType);
Running it on an unmodified My_First_Score results in the following output:
Debug: A ChordRest type: 128
Debug: First ChordRest of score: 1

Running it from Qt Creator/Debugging with a breakpoint upon entering Ms::Score::firstSegment shows in the callstack that the qt_static_metacall created by MOC calls _t->firstSegment().
Because it links the QML call with the default call, this results in a call with Segment::Type::All as internal argument.


A bit of reading into the Qt Documentation: http://doc.qt.io/qt-5/qtqml-cppintegration-data.htm chapter 'Enumeration Types as Signal and Method Parameters':
C++ signals and methods with enumeration-type parameters can be used from QML provided that the enumeration and the signal or method are both declared within the same class, or that the enumeration value is one of those declared in the Qt Namespace.
For QML signals, enum values may be passed as signal parameters using the int type.

Currently possibly affected function links:
Q_INVOKABLE static Ms::Element* Ms::Element::create(Ms::Element::Type type, Score*);
Q_INVOKABLE Ms::Segment* Ms::Segment::firstSegment(Segment::Type s = Segment::Type::All) const;
Q_INVOKABLE void Ms::TimeSig::setSig(int z, int n, TimeSigType st = TimeSigType::NORMAL) { setSig(Fraction(z, n), st); }

EDIT: Ms::Element::create as a static function seems to not be callable from a plugin. Probably this is why qmlPlugin::newElement was created in the first place. I believe the Q_INVOKABLE for this specific function can be safely removed.
Anyone can confirm this?