Unable to assign QJSValue to QColor
Unsolved
QML and Qt Quick
-
As stated here:
http://doc.qt.io/qt-5/qtqml-cppintegration-data.html
and here:
http://doc.qt.io/qt-5/qml-color.html
QColor types should be automatically converted to color when passed to QML. Instead I receive the error:
Unable to assign QJSValue to QColor
Here the relevant declarations in my class:
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) QColor color() { return m_color; } QColor m_color;
On QML side:
import QtQuick 2.0 ListModel { id: myModel } function() { myModel.append( { "myColor": myClass.color } ) } // in delegate Rectangle { width: 200 height: 200 color: myColor }
-
Values must be simple constants; either strings (quoted and optionally within a call to QT_TR_NOOP), boolean values (true, false), numbers, or enumeration values (such as AlignText.AlignHCenter).
So IMO a QColor cannot be assigned to the role myColor. And this in turn causes problem in the delegate.