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. Parse problem with RegExpValidator in large binding
Forum Updated to NodeBB v4.3 + New Features

Parse problem with RegExpValidator in large binding

Scheduled Pinned Locked Moved Solved QML and Qt Quick
7 Posts 2 Posters 1.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.
  • S Offline
    S Offline
    SafaAlfulaij
    wrote on last edited by SafaAlfulaij
    #1

    Sample code:

    validator: {
        if (rootItem.validator == 'test')
            return RegExpValidator {}
        else if (rootItem.validator == 'int')
            return IntValidator {}
        else
            return undefined
    }
    

    I always get Expected token ';' on return RegExpValidator {} and Expected token '}' on else if (rootItem.validator == 'int')

    I dont get problems if a string is returned (It just says that I can't assign a QString to a QValidator).

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet

      AFAIK it should be:

      return RegExpValidator {regExp: /''/}
      

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      S 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi and welcome to devnet

        AFAIK it should be:

        return RegExpValidator {regExp: /''/}
        
        S Offline
        S Offline
        SafaAlfulaij
        wrote on last edited by SafaAlfulaij
        #3

        @SGaist Thanks for your answer.
        But RegExp works well if I used it as a simple binding (no curly brackets and an inline if..else statement).
        And it is supported as the docs says: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          But you are using a RegExpValidator which is a QML type and the documentation of the regExp property explicitly state that you should pass a regular expression in JS syntax.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          S 1 Reply Last reply
          0
          • SGaistS SGaist

            But you are using a RegExpValidator which is a QML type and the documentation of the regExp property explicitly state that you should pass a regular expression in JS syntax.

            S Offline
            S Offline
            SafaAlfulaij
            wrote on last edited by
            #5

            @SGaist I made an edit to the code (even though RegExp works for me). I get the same error with the new code.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Ok, I think I misunderstood your original setup.

              A cleaner way to do that would be to have a validatorName property on your item and you change the validator accordingly. You can then manipulate that property from your rootItem for example.

              WARNING not tested

              YourItem {
                  id: yourItem
              
                  property str validatorName: "test"
              
                  onValidatorNameChanged: {
                      if (validatorName == "int")
                          validator = intval;
                      else if (validatorName == "test")
                          validator = regex;
                      // etc
                     }
                     IntValidator { id: intval  }
                     RegExpValidator { id: regexp; regExp: /""/ }
              }
              

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              S 1 Reply Last reply
              1
              • SGaistS SGaist

                Ok, I think I misunderstood your original setup.

                A cleaner way to do that would be to have a validatorName property on your item and you change the validator accordingly. You can then manipulate that property from your rootItem for example.

                WARNING not tested

                YourItem {
                    id: yourItem
                
                    property str validatorName: "test"
                
                    onValidatorNameChanged: {
                        if (validatorName == "int")
                            validator = intval;
                        else if (validatorName == "test")
                            validator = regex;
                        // etc
                       }
                       IntValidator { id: intval  }
                       RegExpValidator { id: regexp; regExp: /""/ }
                }
                
                S Offline
                S Offline
                SafaAlfulaij
                wrote on last edited by
                #7

                @SGaist Thanks a dozen! It worked! :)

                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