[SOLVED] How to Restrict Unwanted Characters from String List Using QRegExp ?
-
Yes.. For the First Time the Line Edit should Accept only A, B, C & D.. it should Reject J, K, L & M and other Alphabets Like E, F, G, H, I, O, P, Q, R, S....Z
Thanks & Regards...
-
@
QRegExpValidator* validator = new QRegExpValidator( QRegExp( "AJ|BK|CL|DM" ) );
lineEdit->setValidator( validator );
@ -
Thanks for your Suggestion... but this will not work in my case... The string list values may contain different set of items.. First it may contain like which i had mentioned above. the next time it may contain a different set of string items... so what should i do in that case???
-
You should read a QStringList doc ;)
@
QStringList sl;
sl << "AJ" << "BK" << "CL" << "DM";QRegExpValidator* validator = new QRegExpValidator( QRegExp( sl.join( "|" ) ) ); lineEdit->setValidator( validator );
@
-
[quote author="Rochi" date="1361138440"]Thanks for your Suggestion... but this will not work in my case... The string list values may contain different set of items.. First it may contain like which i had mentioned above. the next time it may contain a different set of string items... so what should i do in that case??? [/quote]
Is there any rule that will tell you how that set will change?
-
Sounds like a job for a restricted QComboBox rather than a free text editor.
-
[quote author="slinavipuz" date="1361141106"]
Is there any rule that will tell you how that set will change?[/quote]Yes..... I have a method called stringListType() in that if i pass any of the StringList then it will take will take the corresponding StringList items......
EDIT : Then i have to restrict the characters which are not in the StringList Items.......
-
[quote author="ChrisW67" date="1361141581"]Sounds like a job for a restricted QComboBox rather than a free text editor.
[/quote]Yup, but not completely... for a free text editior we can use a QCompleter for getting the Suggestions of the StringList Items. But in this case, i have to restrict the other characters except the characters of the StringList
-
Whooooo..... Finally i had solved it by myself..... I had pasted the code below.....
@QString regExpression = "(";
for (int i = 0; i < getStringList()->size(); ++i)
{
regExpression.append(getStringList()->at(i) + "|");
}QRegExp rE(regExpression);
q_LineEdit->setValidator(new QRegExpValidator(rE, this));@Thank you all for your suggestions........
Thanks & Regards..
-
Your for loop is equal to my suggestion:
@
sl.join( "|" );
@