0

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.

Percee
  • 449
  • 5
  • 25
  • I don't understand the problem at all - the xml writer has to accept all characters and encode it properly. – chehrlic Jan 15 '21 at 21:01

1 Answers1

1

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

zgyarmati
  • 1,135
  • 8
  • 15
  • Thanks, that is probably the best way. I edited the validate() function of my QValidator-derived class to modify the string and remove illegal HTML characters. – Percee Jan 18 '21 at 14:48