Unsolved QTextBrowser causing a program to crash
-
Hello,
Working with embedded systems I have to rely on RS-232 communication heavily. So far I've been using PuTTY, which can be a pain if you're not sure what the baud rate of a device is when you're attempting to com to it. I'm writing a program which would allow you to dynamically switch between various aspects of the protocol (baud rate, parity, etc...), as well as detect the COM ports which are detected. This program needs to run on Windows and Linux. The program works just fine on Linux, however Windows in an entirely different story.
With all that said, the issue which is causing the program to crash repeatedly is as such:
Whenever the improper baud rate is selected (the device is emitting 38400 and you have 57600, for instance, selected), the output is odd characters. This is entirely expected, however, whenever the odd characters are output to the text browser the program will end up crashing. I've tried cleaning the QString in multiple ways, but it would appear that some sort of strange unicode character outside the specified domain (I'm specifying that the character must be ch <= 0x7F) keeps slipping into what is being entered into the QTextBrowser;
I am adding the QString to the QTextBrowser with insertPlainText(QString str);
The most recent fix that I've attempted to apply is this:
QString Dialog::cleanText(const QString text) { QString temp = text; QChar* str = temp.data(); for(int z = 0; z < temp.size(); z++) { if(str[z] > 0x7F) { str[z] = 0x00; } } return temp; }
Even this ends up allowing unicode characters and crashing the program eventually. Any help is greatly appreciated.
-
Hi
Do you set the text with
void setPlainText(const QString &text)
The setText will try to guess format and Im wondering
if that could crash it. -
hi
I tested with
QByteArray b;
for (int var = 1; var < 255; ++var) {
b.append( var );
}
ui->textBrowser->setText(b);Cant really make it crash giving it values.
What do you think is the difference ?
-
@mrjj I set the text with insertPlainText(const QString &text). Using any of the setText commands won't be useful as they would overwrite the previous text. The RS-232 is non-blocking, so text is incoming in bytes not lines.
To answer your second post, I think the difference is that you're setting the text when I'm inserting it at the end of the current text.