[SOLVED]QtQuick function if else condition issue
-
Traxx, Lucijan just wanted to know the output so it would be easier to understand your problem and find a solution. It was obviously not a fix or a solution. Why don't you post us the output of Lucijans function? Also you didn't provide us your model imei. This model would probably be necessary for a solution.
-
Oh sorry for misreading.Did you mean this ?I purposely leave other message as it is private.I
[Qt Message] Iteration: 0, true
[Qt Message] Iteration: 1, true
[Qt Message] Iteration: 2, true
[Qt Message] Iteration: 3, true
[Qt Message] Iteration: 4, trueand the listmodel is below
@ListModel {
id: imeimodelListElement{imeistring: "354863595" } ListElement{imeistring: "354870672" } ListElement{imeistring: "359050560" } //MY specific ListElement{imeistring: "354875072" } ListElement{imeistring: "358261609" } }
@
-
Yes i meant this. The ListModel shouldn't be the problem, but your function is false for testings. Please replace the else{} in your function with:
@else {
console.log("Iteration: " + i + ", false");
verifyfaildialog.open();
}@After you have done this post us the output again so we can see when it hits the else.
-
Sorry for my typo.Thank you guys for being so helpful.The help is very appreciated
[Qt Message] Iteration: 0, false
[Qt Message] Iteration: 1, false
[Qt Message] Iteration: 2, true
[Qt Message] Iteration: 3, false
[Qt Message] Iteration: 4, false -
bq. Sorry for my typo.Thank you guys for being so helpful.The help is very appreciated
It's no problem and you're welcome.
The third ListElement in your ListModel is your imei. When your function iterates trough the imeis, it checks for your imei and if i look at your output it returns true when it hits the third value. It all looks fine, where is the problem or what do you want to manage?
-
The function is suppose to match listmodel database imei with imei string using qml deviceInfo.imei to query device imei .If the imei match then the testdialog should open otherwise verifyfaildiaolog that open.The problem is if it not match verifyfaildialog open but if it match both dialog open when it should open testdialog only.
If else condition work in my other function and qml signal correctly and expected but this particular function just won't work.
-
Alright. Looks like you just misunderstood the for loop. It iterates trough each Element in your model, it even continues if it already has a dialog open. Opening a dialog is no return or break.
Just replace your for-loop with this one and it should work:
@for(var i = 0; i < imei.count; i++){
if(imei.get(i).imeistring === deviceInfo.imei){
testdialog.open()
return
}
}
verifyfaildialog.open()@It's pretty simple: It iterates trough all of your Elements in your model until it found the imei which matches your imei. If that happens it opens the right dialog and quits the function. It will continue with the lines after the for-loop and open the fail dialog if it could not find your imei in your Model.
For further information about the for-loop please read:
"C++ For-loop Tutorial":http://www.tutorialspoint.com/cplusplus/cpp_for_loop.htm
"Javascript For-loop Tutorial":http://www.w3schools.com/js/js_loop_for.asp -
Thanks,i will try the code tommorrow.Thanks very much for helping me learn new stuff
-
You're welcome. Feel free to ask if you have got more questions and don't forget to add "[Solved]" at the beginning of this threads title.
-
Thanks all.The code work as suggested.This topic is solved