Hi,
I would like to control the input of a QlineEdit in order to avoid the insertion of some characters.
I've written down the subsequent code that every time the user insert a new element in the QLineEdit, controls the input and erase the last character of the line if it is not valid!


Qt Code:
  1. void ElaborationOffset::ElaborationOffset()
  2. {
  3. [...]
  4. par2 = new QLineEdit;
  5. connect(par2,SIGNAL(textChanged(QString)),this,SLOT(updateGraph(QString)));
  6. [...]
  7. }
  8.  
  9. void ElaborationOffset::updateGraph(QString dummy)
  10. {
  11. bool ok;
  12. int pos=0;
  13. QString par2Str = par2->text();
  14.  
  15. QRegExp expr("[-,+]{0,1}[0-9]+[.,,][0-9]+");
  16. QRegExpValidator v(expr, 0);
  17.  
  18. if(v.validate(par2Str,pos) == QValidator::Invalid)
  19. {
  20. par2->backspace();
  21. return;
  22. }
  23.  
  24. [...]
  25. }
To copy to clipboard, switch view to plain text mode 

It works... But the problem is that when I try to insert a non valid char, the updateGraph slot is called 2 times, because of the par2->backspace(); instruction that triggers another signal--->slot call !!!
I think there is no mask that I can use to avoid this problem, because I cannot know the number format (it depends on the particular value)...! For example I can insert -0.0002, but also 12900!!!
Any hints to solve this problem?

Thank you all.
Alex