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!
	
	- void ElaborationOffset::ElaborationOffset() 
- { 
-     [...] 
-     connect(- par2, SIGNAL(- textChanged (QString))- , this- , SLOT(- updateGraph (QString)))- ; 
 
-     [...] 
- } 
-   
- void-  ElaborationOffset ::updateGraph(QString-  dummy )
 
- { 
-     bool ok; 
-     int pos=0; 
-   
-     QRegExp-  expr ("[-,+]{0,1}[0-9]+[.,,][0-9]+")- ; 
 
-   
-     if(- v. validate(- par2Str,pos ) == QValidator::Invalid)
 
-     { 
-         par2->backspace(); 
-         return; 
-     } 
-   
-    [...] 
- } 
        void ElaborationOffset::ElaborationOffset()
{
    [...]
    par2 = new QLineEdit;
    connect(par2,SIGNAL(textChanged(QString)),this,SLOT(updateGraph(QString)));
    [...]
}
void ElaborationOffset::updateGraph(QString dummy)
{
    bool ok;
    int pos=0;
    QString par2Str = par2->text();
    QRegExp expr("[-,+]{0,1}[0-9]+[.,,][0-9]+");
    QRegExpValidator v(expr, 0);
    if(v.validate(par2Str,pos) == QValidator::Invalid)
    {
        par2->backspace();
        return;
    }
   [...]
}
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
				
			
Bookmarks