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
Servers for Qt installer are currently down

Unable to assign QJSValue to QColor

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qcolorcolorqjsvaluec++qml
2 Posts 2 Posters 3.7k Views 1 Watching
  • 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 30 May 2016, 16:04 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
    }
    
    P 1 Reply Last reply 30 May 2016, 16:44
    0
    • M Mark81
      30 May 2016, 16:04

      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
      }
      
      P Offline
      P Offline
      p3c0
      Moderators
      wrote on 30 May 2016, 16:44 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

      2/2

      30 May 2016, 16:44

      • Login

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