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
Forum Updated to NodeBB v4.3 + New Features

QTextBrowser causing a program to crash

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 5 Posters 3.7k Views 3 Watching
  • 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.
  • A Offline
    A Offline
    AlexB89
    wrote on 24 Apr 2016, 00:37 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
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 24 Apr 2016, 07:59 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.

      A 1 Reply Last reply 24 Apr 2016, 17:41
      0
      • M Offline
        M Offline
        mrjj
        Lifetime Qt Champion
        wrote on 24 Apr 2016, 08:08 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
        • M mrjj
          24 Apr 2016, 07:59

          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.

          A Offline
          A Offline
          AlexB89
          wrote on 24 Apr 2016, 17:41 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
          • E Offline
            E Offline
            errxyz
            wrote 30 days ago last edited by
            #5

            hi, did you manage to solve the problem? I am writing a similar program, trying to make something like a read-only terminal out of QTextBrowser

            S 1 Reply Last reply 29 days ago
            0
            • E errxyz
              30 days ago

              hi, did you manage to solve the problem? I am writing a similar program, trying to make something like a read-only terminal out of QTextBrowser

              S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote 29 days ago last edited by
              #6

              @errxyz said in QTextBrowser causing a program to crash:

              hi, did you manage to solve the problem? I am writing a similar program, trying to make something like a read-only terminal out of QTextBrowser

              Hi and welcome to devnet,

              You should create a new topic describing the exact problem you are having, the code that triggers it, etc.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • B Offline
                B Offline
                BugSleeper
                wrote 27 days ago last edited by
                #7

                try
                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] <32)
                {
                str[z] = 0x20;
                }
                }
                return temp;
                }

                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