简体   繁体   中英

Qt Creator setInputMethodHints not work

my main goal right now is to forbid some chars entering in line edit.I want to forbid (!@#$%^&*()) chars, cause i do use SQL Database and someone can damage my database without filters for this chars.I tried to use setInputMask but in this way i can use only alphabets.I need to use '-' sign too for some names like "Anna-Maria". So finally, setInputMethodHints is not working and i don't know what to do. I just need to forbid some "dangerous" chars. If you can, please provide me some source code. Thank you in advance.

Use QRegExpValidator to allow only az AZ 0-9 and '-' character. If you want to add more character just put \\charactor in to the rx(".."); like I did with '-' by adding \\-

QRegExp rx("[a-zA-Z0-9\-]*");
ui.lineEdit->setValidator(new QRegExpValidator(rx,ui.textEdit));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM