Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved QDoubleValidate Switching

    General and Desktop
    qvalidator switch switching line edit
    2
    7
    1845
    Loading More Posts
    • 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
      Dan90 last edited by

      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())
      
      kshegunov 1 Reply Last reply Reply Quote 0
      • kshegunov
        kshegunov Moderators @Dan90 last edited by

        @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 Reply Quote 0
        • D
          Dan90 @kshegunov last edited by

          @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

          kshegunov 1 Reply Last reply Reply Quote 0
          • kshegunov
            kshegunov Moderators @Dan90 last edited by

            @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 Reply Quote 0
            • D
              Dan90 @kshegunov last edited by

              @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 ?

              kshegunov 1 Reply Last reply Reply Quote 0
              • kshegunov
                kshegunov Moderators @Dan90 last edited by 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.

                Read and abide by the Qt Code of Conduct

                D 1 Reply Last reply Reply Quote 1
                • D
                  Dan90 @kshegunov last edited by

                  @kshegunov
                  Allright, thanks for the help.

                  1 Reply Last reply Reply Quote 1
                  • First post
                    Last post