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. QPlainTextEdit Clearing Problems

QPlainTextEdit Clearing Problems

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 478 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.
  • A Offline
    A Offline
    admkrk
    wrote on last edited by
    #1

    Hi, This kind of hard to describe. I am working on a simple front end for NASM that has a text editor and and also a hex editor. The text editor part works fine, but when I try to clear the QPlainTextEdit for the hex editor I have problems. If I use clear() or setPlainText("") I get

    FFFFFFFFFFFFFFF0
    

    inserted at the start of the page, before my header. If I just use setPlainText(header) I get the same, only the cursor is at the start of the header. The first F is only selectable if I double click the text. Backspacing on that F not only adds the text back but adds it again also. A few random clicks produces this

    FFFFFFFFFFFF FFF 0   FFF  FFF FFFF FFF  0   Offset    00 01 02 03 04 
    00000000   0 5 06 07 08 09 0A 0B 0C 0D 0E 0F
    00000000  
    00000000
    

    and this is what it should look like

    Offset    00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
    00000000
    

    The only difference is the sloppy way I format the hex editor

    if(isHex)
        {
            if(ui->plainTextEdit->textCursor().positionInBlock() == 0)
            {
                int lineNumber = (ui->plainTextEdit->textCursor().blockNumber() - 1) * 16;
                ui->plainTextEdit->insertPlainText(QString("%1").arg(lineNumber, 8, 16, QChar('0')).toUpper());
                ui->plainTextEdit->insertPlainText("  ");
            }
    
            if((ui->plainTextEdit->textCursor().positionInBlock() - 10) % 3 == 2)
            {
                ui->plainTextEdit->insertPlainText(" ");
            }
    
            if(ui->plainTextEdit->textCursor().positionInBlock() > 57)
            {
                ui->plainTextEdit->insertPlainText("\n");
            }
        }
    

    While bad form, I do not understand how this would cause the problems I am having.

    jsulmJ JonBJ 2 Replies Last reply
    0
    • A admkrk

      Hi, This kind of hard to describe. I am working on a simple front end for NASM that has a text editor and and also a hex editor. The text editor part works fine, but when I try to clear the QPlainTextEdit for the hex editor I have problems. If I use clear() or setPlainText("") I get

      FFFFFFFFFFFFFFF0
      

      inserted at the start of the page, before my header. If I just use setPlainText(header) I get the same, only the cursor is at the start of the header. The first F is only selectable if I double click the text. Backspacing on that F not only adds the text back but adds it again also. A few random clicks produces this

      FFFFFFFFFFFF FFF 0   FFF  FFF FFFF FFF  0   Offset    00 01 02 03 04 
      00000000   0 5 06 07 08 09 0A 0B 0C 0D 0E 0F
      00000000  
      00000000
      

      and this is what it should look like

      Offset    00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
      00000000
      

      The only difference is the sloppy way I format the hex editor

      if(isHex)
          {
              if(ui->plainTextEdit->textCursor().positionInBlock() == 0)
              {
                  int lineNumber = (ui->plainTextEdit->textCursor().blockNumber() - 1) * 16;
                  ui->plainTextEdit->insertPlainText(QString("%1").arg(lineNumber, 8, 16, QChar('0')).toUpper());
                  ui->plainTextEdit->insertPlainText("  ");
              }
      
              if((ui->plainTextEdit->textCursor().positionInBlock() - 10) % 3 == 2)
              {
                  ui->plainTextEdit->insertPlainText(" ");
              }
      
              if(ui->plainTextEdit->textCursor().positionInBlock() > 57)
              {
                  ui->plainTextEdit->insertPlainText("\n");
              }
          }
      

      While bad form, I do not understand how this would cause the problems I am having.

      jsulmJ Online
      jsulmJ Online
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @admkrk Where is this code located?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • A admkrk

        Hi, This kind of hard to describe. I am working on a simple front end for NASM that has a text editor and and also a hex editor. The text editor part works fine, but when I try to clear the QPlainTextEdit for the hex editor I have problems. If I use clear() or setPlainText("") I get

        FFFFFFFFFFFFFFF0
        

        inserted at the start of the page, before my header. If I just use setPlainText(header) I get the same, only the cursor is at the start of the header. The first F is only selectable if I double click the text. Backspacing on that F not only adds the text back but adds it again also. A few random clicks produces this

        FFFFFFFFFFFF FFF 0   FFF  FFF FFFF FFF  0   Offset    00 01 02 03 04 
        00000000   0 5 06 07 08 09 0A 0B 0C 0D 0E 0F
        00000000  
        00000000
        

        and this is what it should look like

        Offset    00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
        00000000
        

        The only difference is the sloppy way I format the hex editor

        if(isHex)
            {
                if(ui->plainTextEdit->textCursor().positionInBlock() == 0)
                {
                    int lineNumber = (ui->plainTextEdit->textCursor().blockNumber() - 1) * 16;
                    ui->plainTextEdit->insertPlainText(QString("%1").arg(lineNumber, 8, 16, QChar('0')).toUpper());
                    ui->plainTextEdit->insertPlainText("  ");
                }
        
                if((ui->plainTextEdit->textCursor().positionInBlock() - 10) % 3 == 2)
                {
                    ui->plainTextEdit->insertPlainText(" ");
                }
        
                if(ui->plainTextEdit->textCursor().positionInBlock() > 57)
                {
                    ui->plainTextEdit->insertPlainText("\n");
                }
            }
        

        While bad form, I do not understand how this would cause the problems I am having.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #3

        @admkrk
        Just an observation, because I like spotting coincidences!

        FFFFFFFFFFFFFFF0

        This is -16 in hex, in an 8-byte/64-bit integer.

        int lineNumber = (ui->plainTextEdit->textCursor().blockNumber() - 1) * 16;
        ui->plainTextEdit->insertPlainText(QString("%1").arg(lineNumber, 8, 16, QChar('0')).toUpper());

        This would deliver -16 => FFFFFFFFFFFFFFF0 if .blockNumber() is 0.

        Coincidence? :)

        1 Reply Last reply
        3
        • A Offline
          A Offline
          admkrk
          wrote on last edited by
          #4

          @jsulm said in QPlainTextEdit Clearing Problems:

          @admkrk Where is this code located?

          It is in a getCursorPosition() function I use to track the cursor in the status bar.

          I never anticipated that it would ever read on the first line since the header takes up that line. It looks like the cursor is put back to the start before the header is inserted, after the initial time. I have been bitten like this before, but it involved when widgets were made visible.

          Thanks for the good eyes JonB.

          1 Reply Last reply
          2

          • Login

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