Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTextBrowser causing a program to crash

QTextBrowser causing a program to crash

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • AlexB89A Offline
    AlexB89A Offline
    AlexB89
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      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.

      AlexB89A 1 Reply Last reply
      0
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by mrjj
        #3

        hi
        I tested with
        QByteArray b;
        for (int var = 1; var < 255; ++var) {
        b.append( var );
        }
        ui->textBrowser->setText(b);

        test

        Cant really make it crash giving it values.

        What do you think is the difference ?

        1 Reply Last reply
        0
        • mrjjM mrjj

          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.

          AlexB89A Offline
          AlexB89A Offline
          AlexB89
          wrote on last edited by AlexB89
          #4

          @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.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved