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]QtQuick function if else condition issue
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]QtQuick function if else condition issue

Scheduled Pinned Locked Moved QML and Qt Quick
13 Posts 3 Posters 23.3k 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.
  • O Offline
    O Offline
    onek24
    wrote on last edited by
    #4

    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.

    1 Reply Last reply
    0
    • T Offline
      T Offline
      Traxx
      wrote on last edited by
      #5

      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, true

      and the listmodel is below

      @ListModel {
      id: imeimodel

              ListElement{imeistring: "354863595" }
              ListElement{imeistring: "354870672" }
              ListElement{imeistring: "359050560" } //MY specific
              ListElement{imeistring: "354875072" }
              ListElement{imeistring: "358261609" }
       }
      

      @

      1 Reply Last reply
      0
      • O Offline
        O Offline
        onek24
        wrote on last edited by
        #6

        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.

        1 Reply Last reply
        0
        • T Offline
          T Offline
          Traxx
          wrote on last edited by
          #7

          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

          1 Reply Last reply
          0
          • O Offline
            O Offline
            onek24
            wrote on last edited by
            #8

            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?

            1 Reply Last reply
            0
            • T Offline
              T Offline
              Traxx
              wrote on last edited by
              #9

              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.

              1 Reply Last reply
              0
              • O Offline
                O Offline
                onek24
                wrote on last edited by
                #10

                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

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  Traxx
                  wrote on last edited by
                  #11

                  Thanks,i will try the code tommorrow.Thanks very much for helping me learn new stuff

                  1 Reply Last reply
                  0
                  • O Offline
                    O Offline
                    onek24
                    wrote on last edited by
                    #12

                    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.

                    1 Reply Last reply
                    0
                    • T Offline
                      T Offline
                      Traxx
                      wrote on last edited by
                      #13

                      Thanks all.The code work as suggested.This topic is solved

                      1 Reply Last reply
                      0

                      • Login

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