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. [solved]QML component: Cannot assign multiple values to a singular property
Forum Updated to NodeBB v4.3 + New Features

[solved]QML component: Cannot assign multiple values to a singular property

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 7.2k 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.
  • K Offline
    K Offline
    kahon
    wrote on 31 May 2012, 16:59 last edited by
    #1

    Anybody knows what does this sentence mean? Because when I use the next component, my application don't execute at all.
    It crash here
    @
    import QtQuick 1.0
    import "../commons/fakeSymbianComponents"
    import ".."
    import "../commons/jsonpath-0.8.0.js" as JsonPath
    Page {
    id: root
    property variant data

    property bool m_json_debug: true
    property variant dates
    function getDates(){
        return JsonPath.jsonPath(data,"$..prediccion[*].fecha")
    }
    
    property string name_window: "> CityDetail :"
    
    function gDebug(str,section){
        var display = m_debug
        if(section!=undefined)
            display = section && m_debug
        if (display)
            console.log(name_window + str)
    }
    
    CommonHeader{ // here- <-------------------------------------------------------------------------
        section: qsTr("MI CIUDAD")
        z:100
    }
    
    Text{
        id:textDate
        anchors.centerIn: parent
    }
    
    onDataChanged: {
        dates = getDates()
        gDebug("DATA CHANGED:" +data)
        gDebug("FECHA:" +  getDates()[0])
    }
    

    }
    @

    The CommonHeader component is:

    @
    import QtQuick 1.0
    import "commons"
    Item {
    id: root
    property string section:""
    property variant lineColor: "#96D7FF"
    property bool searchActive: true
    width: if(parent)parent.width
    height: infoSection.height+rectSearch.height
    signal search(string filter);
    Rectangle {
    id: infoSection
    anchors.top:parent.top
    height: 30
    width: parent.width
    color:"#494A4B"
    Text{
    id: textSection
    text:section
    anchors.verticalCenter: parent.verticalCenter
    anchors.left: parent.left
    anchors.leftMargin: 12
    font.pixelSize: 18
    color: "white"
    }
    Image {
    id: logo
    source: "images/logo.png"
    anchors.right: parent.right
    anchors.verticalCenter: parent.verticalCenter
    anchors.rightMargin: 10
    }
    Rectangle {
    id: lineUp
    height: 1
    width: parent.width
    color:lineColor
    anchors.top:parent.top
    }
    Rectangle {
    id: lineDown
    height: 1
    width: parent.width
    color:lineColor
    anchors.bottom:parent.bottom
    }
    }
    RectSearch {
    id:rectSearch
    anchors.top: infoSection.bottom
    width: parent.width
    visible: searchActive
    height: if(searchActive)50
    else 0

    }
    Component.onCompleted: {
        rectSearch.search.connect(root.search)
    }
    

    }
    @

    the RectSearch component is:

    @
    import QtQuick 1.0
    import "../commons"

    Rectangle{
    signal search(string filter);
    height: backSearch.sourceSize.height; width: 360
    z:10
    gradient: Gradient { GradientStop {color:"#494A4B";position:0}GradientStop {color:"#2E2E2F";position:1}}
    Rectangle{
    id:backSearch
    anchors.verticalCenter: parent.verticalCenter
    FormItem{
    id:tfNews
    radius: 15
    color:"white"
    anchors.left: parent.left
    anchors.verticalCenter: parent.verticalCenter
    anchors.leftMargin: 6
    width: 290
    height: 30
    }

        Button{
            id: searchButton
            anchors.left: tfNews.right
            anchors.verticalCenter: parent.verticalCenter
            sInactiveSource: "../images/button_search_off.png"
            sActiveSource: "../images/button_search_on.png"
            text:"Buscar"
            anchors.leftMargin: 12
            onButtonClicked: {
                search(tfNews.getText())
            }
        }
    }
    

    }
    @

    any idea why is it happening? I have no idea really.

    Thanks for your help!
    Fernando Moreno Ruiz.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      chriadam
      wrote on 1 Jun 2012, 00:43 last edited by
      #2

      Can you paste the full error, including line number and column information?

      I haven't looked closely at the issue, but it could be any number of things:

      QML types defined in C++ can have a "default property" -- that is, the property that a value is assigned to, if no property name is given.

      One prominent example of such a default property is the "children" property of the Item type.
      You can do:

      @
      Item {
      id: root

      Item {
          id: child1
      }
      
      Item {
          id: child2
      }
      

      }
      @

      and this is identical to

      @
      Item {
      id: root

      children: [
          Item {
              id: child1
          },
          Item {
              id: child2
          }
      ]
      

      }
      @

      Now it's possible that the Page component has a default property which is a singular Item, and thus attempting to assign both a CommonHeader and a Text element (ie, an array of Items) to that singular Item property, is causing a problem.

      Alternatively, there may be a property list<someType> property somewhere, which is being assigned or bound to another property, somewhere, which could also cause this error.

      Cheers,
      Chris.

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kahon
        wrote on 1 Jun 2012, 09:50 last edited by
        #3

        Hi Chris,
        Thank you too much because of your reply. I did solve this typing:
        @
        children:[
        Text{
        id:textDate
        anchors.centerIn: parent
        },

            CommonHeader{
                searchActive: false
                section: qsTr("MI CIUDAD")
                z:100
            }
        ]
        

        @
        instance of doing by default property. I don't know why it solved the problem. But I understood that you told me almost everything. I'm not sure from where it is accessing to the component. But doing explicit code, it doesn't happen.

        Best,
        Fernando.

        1 Reply Last reply
        0

        3/3

        1 Jun 2012, 09:50

        • Login

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