【问题标题】:Qt Creator setInputMethodHints not workQt Creator setInputMethodHints 不起作用
【发布时间】:2013-07-20 13:01:04
【问题描述】:

我现在的主要目标是禁止在行编辑中输入一些字符。我想禁止 (!@#$%^&*()) 字符,因为我确实使用 SQL 数据库,有人可能会在没有过滤器的情况下损坏我的数据库对于这个字符。我尝试使用 setInputMask,但这样我只能使用字母。对于“Anna-Maria”等名称,我也需要使用“-”符号。 所以最后,setInputMethodHints 不起作用,我不知道该怎么做。 我只需要禁止一些“危险”字符。 如果可以的话,请给我一些源代码。 提前谢谢你。

【问题讨论】:

    标签: qt methods chars hints


    【解决方案1】:

    使用 QRegExpValidator 只允许 a-z A-Z 0-9 和 '-' 字符。如果您想添加更多字符,只需将 \charactor 放入 rx("..");就像我对 '-' 所做的那样,添加 \-

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

    【讨论】:

    • 非常感谢!昨天我为此编写了自己的算法,但你的方法更好。现在一切正常。再次感谢;)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多