4

Can QRegExpValidator be used with QTextEdit widget ?

I tried to implement through setValidator() and also set also the qtextedit as parent object. But its not working.

asit_dhal
  • 1,239
  • 19
  • 35
  • Do you mean `QLineEdit`? I don't see `setValidator()` method in `QTextEdit` class. As of `QLineEdit`, validator should work fine, need more information to see where the error is. – SpongeBobFan Jul 03 '13 at 11:48
  • I need to use in QTextEdit. I also didn't see setValidator() function. So, I want some examples of the implementation(Can this be used in any other way?). – asit_dhal Jul 03 '13 at 11:51

2 Answers2

2

You should use
virtual QValidator::State QRegExpValidator::validate(QString & input, int & pos) const
or
bool QRegExp::exactMatch(const QString & str) const
by yourself. It should not be hard, you just need to determine where to start validate.

SpongeBobFan
  • 964
  • 5
  • 13
  • Can you give me some example or link where all these things have already been done ? – asit_dhal Jul 03 '13 at 12:55
  • validate() can only be called if can set the validator with qtextedit. – asit_dhal Jul 03 '13 at 13:04
  • 1
    I can't provide any example, but it should be easy to connect your slot to `textChanged()` signal (or whatever event you want to be a trigger for validation) and call either `QRegExpValidator::validate()` (I'm sure it can be used without setting the validator to QTextEdit), or `QRegExp::exactMatch()`. You will need to provide information of validation status to user by yourself. All of it should be easy to implement – SpongeBobFan Jul 04 '13 at 03:36
-1

You can do the following things

  • define another slot that will be called when textChanged() signal is emitted
  • emit a signal with two parameters(data in qtextedit and length of same data)
  • connect the validate() slot with the above slots
asitdhal
  • 621
  • 2
  • 7
  • 15