Reputation: 469
I have a Qt application that has a bunch of QLineEdit, QTextEdit etc that the user can modify and put any text he likes.
When saving in this application a XML file is written, partly from what the user has put in these fields. Then the XML file is transformed to HTML through saxonb-xslt.
The problem is that currently the user can enter a range of illegal HTML characters (from 128 to 156 on 1 byte) in these fields, so the XML won't be transformed by saxonb (it rejects it because of illegal HTML characters).
The solution I imagined is creating my own QIODevice overloaded class, and modify the writeData method to transform the data back into a QString, iterate on the QChar and remove every QChar on 1 byte between 128 and 156.
Now this should work in theory, but my question is: I can't be the first one to have this problem, so isn't there a way that can be done easily through a Qt class/method for example? I looked for an already made solution but didn't find it.
Upvotes: 0
Views: 445
Reputation: 1153
I think to best way to handle this is to do input validation already at the input fields. Qt has support for this, see the documentation of the QValidator class and these SO questions: Qt QLineEdit Input Validation and (becauese QTextEdit doesn't have support for validators out of the box): QRegExpValidator with QTextEdit
Upvotes: 1