Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QDoubleValidate Switching
QtWS25 Last Chance

QDoubleValidate Switching

Scheduled Pinned Locked Moved Solved General and Desktop
qvalidatorswitchswitchingline edit
7 Posts 2 Posters 2.4k Views
  • 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.
  • D Offline
    D Offline
    Dan90
    wrote on last edited by
    #1

    Hi everyone,

    i've been struggling with the validation of my QDoubleValidator. I've created a QDoubleValidator object, set the range and set it to be the Validator of a lineEdit object. This works just fine, but when I try to switch through the QValidator::State, I get a compiler error telling me that there is no matching function for call to the validate Method.

    The Code:

    switch(ui->lineEdit1->validator()->validate(ui->lineEdit1->text(), 0))
    {
    case QValidator::Acceptable: /* Do Something */ ;
    ...
    }
    

    The first line produces the compiler error:

    no matching function for call to 'QValidator::validate() const'   switch(ui->lineEdit1->validator()->validate())
    
    kshegunovK 1 Reply Last reply
    0
    • D Dan90

      Hi everyone,

      i've been struggling with the validation of my QDoubleValidator. I've created a QDoubleValidator object, set the range and set it to be the Validator of a lineEdit object. This works just fine, but when I try to switch through the QValidator::State, I get a compiler error telling me that there is no matching function for call to the validate Method.

      The Code:

      switch(ui->lineEdit1->validator()->validate(ui->lineEdit1->text(), 0))
      {
      case QValidator::Acceptable: /* Do Something */ ;
      ...
      }
      

      The first line produces the compiler error:

      no matching function for call to 'QValidator::validate() const'   switch(ui->lineEdit1->validator()->validate())
      
      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      @Dan90
      Hello,
      The first line can't be producing that error, as the compiler is complaining about:

      switch(ui->lineEdit1->validator()->validate())
      

      Kind regards.

      Read and abide by the Qt Code of Conduct

      D 1 Reply Last reply
      0
      • kshegunovK kshegunov

        @Dan90
        Hello,
        The first line can't be producing that error, as the compiler is complaining about:

        switch(ui->lineEdit1->validator()->validate())
        

        Kind regards.

        D Offline
        D Offline
        Dan90
        wrote on last edited by
        #3

        @kshegunov
        Hi,

        I don't get it. the first line of the Code i posted is

        switch(ui->lineEdit1->validator()->validate(ui->lineEdit1->text(), 0))
        

        and the compiler complains about

        switch(ui->lineEdit1->validator()->validate()
        

        which is exactly the first line. How is the first line not producing this error ?

        Regards,
        Daniel

        kshegunovK 1 Reply Last reply
        0
        • D Dan90

          @kshegunov
          Hi,

          I don't get it. the first line of the Code i posted is

          switch(ui->lineEdit1->validator()->validate(ui->lineEdit1->text(), 0))
          

          and the compiler complains about

          switch(ui->lineEdit1->validator()->validate()
          

          which is exactly the first line. How is the first line not producing this error ?

          Regards,
          Daniel

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by
          #4

          @Dan90
          Hello Daniel,

          ui->lineEdit1->validator()->validate()
          

          is different from:

          ui->lineEdit1->validator()->validate(ui->lineEdit1->text(), 0)
          

          Note that the compiler is complaining abut a function that's called without arguments. You could verify that by going to the exact line the compiler is issuing the error for, and check what method is invoked there.

          Kind regards.

          Read and abide by the Qt Code of Conduct

          D 1 Reply Last reply
          0
          • kshegunovK kshegunov

            @Dan90
            Hello Daniel,

            ui->lineEdit1->validator()->validate()
            

            is different from:

            ui->lineEdit1->validator()->validate(ui->lineEdit1->text(), 0)
            

            Note that the compiler is complaining abut a function that's called without arguments. You could verify that by going to the exact line the compiler is issuing the error for, and check what method is invoked there.

            Kind regards.

            D Offline
            D Offline
            Dan90
            wrote on last edited by
            #5

            @kshegunov

            Hi,

            I have now declared

            QString text = ui->lineEdit1->text();
            int pos = 0;
            

            and changed

            ui->lineEdit1->validator()->validate(ui->lineEdit1->text(), 0);
            

            to

            ui->lineEdit1->validator()->validate(text,pos);
            

            and it works perfectly. Can you tell me where the difference ist between declaring the variables first and then passing the variables to the function and directly passing the objects ?

            kshegunovK 1 Reply Last reply
            0
            • D Dan90

              @kshegunov

              Hi,

              I have now declared

              QString text = ui->lineEdit1->text();
              int pos = 0;
              

              and changed

              ui->lineEdit1->validator()->validate(ui->lineEdit1->text(), 0);
              

              to

              ui->lineEdit1->validator()->validate(text,pos);
              

              and it works perfectly. Can you tell me where the difference ist between declaring the variables first and then passing the variables to the function and directly passing the objects ?

              kshegunovK Offline
              kshegunovK Offline
              kshegunov
              Moderators
              wrote on last edited by kshegunov
              #6

              @Dan90
              Aha, yes, of course. I completely missed that, sorry. Notice that the parameters for QValidator::validate are references. So while ui->lineEdit1->text() you can pass to it (although it will not work as expected), you can't pass 0 as a second parameter (it expects int &). The compiler error however looks totally unrelated, whence the confusion.

              Kind regards.

              Read and abide by the Qt Code of Conduct

              D 1 Reply Last reply
              1
              • kshegunovK kshegunov

                @Dan90
                Aha, yes, of course. I completely missed that, sorry. Notice that the parameters for QValidator::validate are references. So while ui->lineEdit1->text() you can pass to it (although it will not work as expected), you can't pass 0 as a second parameter (it expects int &). The compiler error however looks totally unrelated, whence the confusion.

                Kind regards.

                D Offline
                D Offline
                Dan90
                wrote on last edited by
                #7

                @kshegunov
                Allright, thanks for the help.

                1 Reply Last reply
                1

                • Login

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