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] QLineEdit and QValidator issue
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QLineEdit and QValidator issue

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

    Hi,

    If I use QLineEdit::setValidator() once, everything works fine. But strange things happens when I call QLineEdit::setValidator() many times (with different validators).

    Here is my test case: https://github.com/emanuel-koczwara/qt-validator-test

    For example, if you enter an ip address (ipValidator works at that time) and you click pushButton, then ipValidator is replaced by intValidator (and ip address is replaced by an int value). New validator doesn't work at first, you can enter any character, but if you use backspace, then the validator starts working. Any ideas?

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      Hi,
      Couldn't think of a solution so fast, but as a work around, after setting the new validator you might want to clear the QLineEdit text? That might do the trick?
      Hmm, you do set a new value in the lineEdit. Would you be so kind to post that piece of code? Then we are able to regenerate the problem our self.
      Maybe this will help:
      @
      setValidator(0); // remove old seperator
      ui->lineEdit->setText(""); // clear the old text
      setValidator(<new one>); // Set new validator
      ui->lineEdit->setText(QString::number(5)); // set new value in lineedit
      @
      There might be some issue when setting a new validator on a LineEdit when the text in the lineEdit does not match the given validator. So to be sure, first clear the text, then set the new validator, then set a new 'valid' text.

      Greetz, Jeroen

      1 Reply Last reply
      0
      • E Offline
        E Offline
        emanuel_k
        wrote on last edited by
        #3

        Hi,

        Ok, solved. I need to: 1) reset old validator 2) set new text 3) set new validator.

        Thanks

        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