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. [Solved] Validating when a button is pressed
QtWS25 Last Chance

[Solved] Validating when a button is pressed

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 1.7k 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.
  • E Offline
    E Offline
    ephe
    wrote on last edited by
    #1

    I just tried to validate a QLineEdit.
    I have set a QValidator which checks if the entered text is between 0 and 100. Now only values between 0 and 100 can be entered, which is fine.
    But is it also possible to let the user enter everything and check afterwards if it is a valid input?

    I know that the usability is better if the user cannot even enter wrong values, but still sometimes I would like to validate after the focus moved to the next element or if "OK" was pressed.

    1 Reply Last reply
    0
    • K Offline
      K Offline
      Kxyu
      wrote on last edited by
      #2

      Let me explain you how to act in such cases (before posting a question)

      So you have a QValidator object that is ok for you. But it works with QLineEdit in some specific way you want to avoid. That means you shouldnt call setValidator.

      Next. What a QValidator does? It (omg) validates!! That means that the job of this class is to check if string is ok. And probably, it has some publick inteface for that. So let's have a look a the class reference ... and .... voila, it has validate method, which you can use anywhere you want.

      What's the moral of all that? Use qt reference and your mind. Both are awesome.

      1 Reply Last reply
      0
      • F Offline
        F Offline
        fluca1978
        wrote on last edited by
        #3

        [quote author="saho" date="1320674768"]
        But is it also possible to let the user enter everything and check afterwards if it is a valid input?
        [/quote]

        Connect a slot to the focus signals (which one you are interested in) and call the validator's validate method there, without having to tying the validator to the line editor.

        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