Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Unable to assign QJSValue to QColor

Unable to assign QJSValue to QColor

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qcolorcolorqjsvaluec++qml
2 Posts 2 Posters 3.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mark81
    wrote on last edited by
    #1

    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
    }
    
    p3c0P 1 Reply Last reply
    0
    • M Mark81

      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
      }
      
      p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi @Mark81,
      As per the docs:

      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.

      157

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved