[solved]QML component: Cannot assign multiple values to a singular property
-
wrote on 31 May 2012, 16:59 last edited by
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 dataproperty 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. -
wrote on 1 Jun 2012, 00:43 last edited by
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: rootItem { id: child1 } Item { id: child2 }
}
@and this is identical to
@
Item {
id: rootchildren: [ 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. -
wrote on 1 Jun 2012, 09:50 last edited by
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.
3/3