[SOLVED] Convert listelement role to string
-
Hello all.Can someone show me how to convert listelement role to to string.I post the example i use to get the string but only the first listelement is succesful.The rest not.
@
Model.qml
ListModel {
id: model
ListElement{names: "354873595" }
ListElement{names: "354700672" }
ListElement{names: "359033560" }
ListElement{names: "354875672" }
ListElement{names: "352500609" }
}
@@
MainPage.qml
function match() {
if (topname.text == somename.text)
testdialog.open()
else {
faildialog.open()
}
}
Model {
id: namemodel
}
Text {
id: topname
visible: false
text: "2671634"
}
Text {
id: somename
visible: false
text: names
}@I try to use "namemodel.get(0).name" but only the first is read while the rest is not read.
-
Do you mean “namemodel.get(0).names” ?
Do you miss 's'? -
ahhh,sorry a typo.The get() function work but only applied to the first element,the rest cannot be match.
-
Please show your code completely.
especially, where you call namemodel.get(i).name -
Sorry for the confusion but it is complete code.I actually try multiple way to get all string but none work and "namemodel.get()" is just one of the method i try.Previous tried some of the method below.Weird is if i use listview,all the listelement data is shown but i just want to compare the listelement data with other data only.Thanks very much
@MainPage.qml
function match() {
if (topname.text == somename.text)
testdialog.open()
else {
faildialog.open()
}
}
Model {
id: namemodel
}
Text {
id: topname
visible: false
text: "2671634"
}
Text {
id: somename
visible: false
text: namemodel.get(0).names //ONLY WORK ON FIRST LISTELEMENT
}@@MainPage.qml
function match() {
if (topname.text == somename.text)
testdialog.open()
else {
faildialog.open()
}
}
Model {
id: namemodel
}
Text {
id: topname
visible: false
text: "2671634"
}
Text {
id: somename
visible: false
text: namemodel.names
}@ -
try
@
ListModel {
id: myModel
ListElement{names: "354873595" }
ListElement{names: "354700672" }
ListElement{names: "359033560" }
ListElement{names: "354875672" }
ListElement{names: "352500609" }Component.onCompleted: { for(var i=0;i<count;i++) console.log(myModel.get(i).names) }
}
@
Do you see names are printed? -
I never use console.log before but did you mean the qt message as shown?
!http://imageshack.us/photo/my-images/89/3few.png/()! -
I can print all names, so myModel.get(i).names works fine.
Starting H:\Qt\Qt5.2.0\5.2.0\msvc2010_opengl\bin\qmlscene.exe...
354873595
354700672
359033560
354875672
352500609 -
Thank you very very very much for your help.Qmlscene is not available since i use nokia QtSdk and my target is symbian.I will update the title if i manage to match the string.
-
I have change the MainPage a bit to follow Vicent007 example and it is not working but that is not the point.Why if i use "for(var i=0;i<count;i++)" the match() function is not working but if i comment it out it is working with either testdialog or faildialog open.If i use it,no dialog show so i assume the match() function not working.Thank you
@MainPage.qml
function match() {
if (topname.text == somename.text)
testdialog.open()
else {
faildialog.open()
}
}
Model { //TO IMPORT Model.qml
id: namemodel
}
Text {
id: topname
visible: false
text: "2671634"
}
Text {
id: somename
visible: false
}
Component.onCompleted: {
for(var i=0;i<count;i++)
somename.text = namemodel.get(0).imeistring
match() //FUNCTION}
@ -
{ } is missing !!
@
Component.onCompleted: {
for(var i=0;i<count;i++) {
somename.text = namemodel.get(i).imeistring
match() //FUNCTION
}
}
@ -
Weird,putting {} didn't make difference.No dialog show if use the javascript.Once i comment it out the dialog show again.
-
Did you add break points to track your code?
-
Errr,what is break point?
-
now i know,i will try