Results 1 to 4 of 4

Thread: How to manipulate a text in QTextEdit

  1. #1
    Join Date
    Mar 2015
    Posts
    24
    Thanks
    20
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Windows

    Question How to manipulate a text in QTextEdit

    Hi folk!
    I'm trying to make a program to manipulate a text in a QTextEdit and show it after changes in the QTextEdit again. the first problem is that I'm completely newbie. the data is this:

    Qt Code:
    1. 00000000000000000000000000000000FEFFFF01FEFFFF03FFFFFF07FFFFFF070F0080070F0080070F0080070F0080070F0080070F0080070F0080070F0080070F0080070F0080070F0080070F0080070F0080070F0080071F00C007FFFFFF07FFFFFF03FEFFFF03FCFFFF010000000000000000000000000000000000000000
    2. 00000000000000000000000000000000FFFFFF07FFFFFF07FFFFFF07FFFFFF07000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
    3. 000000000000000000000000000000000FE0FF070FF0FF070FF0FF070FF0FF070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070F788007FF7F8007FF7F8007FE3F8007FC1F80070000000000000000000000000000000000000000
    4. 000000000000000000000000000000000FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF8C007FFFFFF07FFFFFF07FEFFFF03FCFFFF010000000000000000000000000000000000000000
    5. 00000000000000000000000000000000FF3F0000FF7F0000FF7F0000FF7F0000007800000078000000780000007800000078000000780000007800000078000000780000007800000078000000780000007800000078000000780000FFFFFF07FFFFFF07FFFFFF07FFFFFF070000000000000000000000000000000000000000
    6. 00000000000000000000000000000000FF3F8007FF7F8007FF7F8007FF7F80070F7880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF8C0070FF0FF070FF0FF070FF0FF030FC0FF010000000000000000000000000000000000000000
    7. 00000000000000000000000000000000FCFFFF01FEFFFF03FFFFFF07FFFFFF070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF8C0070FF0FF070FF0FF070FF0FF030FC0FF010000000000000000000000000000000000000000
    8. 000000000000000000000000000000000F0000000F0000000F0000000F0000000F0000000F0000000F0000000F0000000F0000000F0000000F0000000F0000000F0000000F0000000F0000000F0000000F0000000F0000001F000000FFFFFF07FFFFFF07FEFFFF07FCFFFF070000000000000000000000000000000000000000
    9. 00000000000000000000000000000000FCFFFF01FEFFFF03FFFFFF07FFFFFF070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880071FF8C007FFFFFF07FFFFFF07FEFFFF03FCFFFF010000000000000000000000000000000000000000
    10. 00000000000000000000000000000000FC3F8007FE7F8007FF7F8007FF7F80070F7880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF8C007FFFFFF07FFFFFF03FEFFFF03FCFFFF010000000000000000000000000000000000000000
    To copy to clipboard, switch view to plain text mode 

    the scenario is this:
    When I put the data(above data) in the QTextEdit and push the button, the program put this string ",0x" after each 8 character. somthings like this:


    Qt Code:
    1. 000000000,0x000000000,0x00000000,0x0000000F,0xEFFFF01F,0xEFFFF03F,...
    To copy to clipboard, switch view to plain text mode 

    and show it on the QTextEdit.(replace)

    I need to a simple guidance.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to manipulate a text in QTextEdit

    That's not really related to QTextEdit, just basic string manipulation.
    http://doc.qt.io/qt-5/qstring.html#insert

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    Ryan111 (29th March 2015)

  4. #3
    Join Date
    Mar 2015
    Posts
    24
    Thanks
    20
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Windows

    Default Re: How to manipulate a text in QTextEdit

    Quote Originally Posted by anda_skoa View Post
    That's not really related to QTextEdit, just basic string manipulation.
    http://doc.qt.io/qt-5/qstring.html#insert

    Cheers,
    _
    Thanks!
    that works but not correctly! look:



    as you can see, after several insert, it cannot put ",0x" string anymore. why? the code is this:

    Qt Code:
    1. void MainWindow::on_pushButton_clicked()
    2. {
    3. QString txt = ui->textEdit->toPlainText();
    4.  
    5. for (quint32 t = 0 ; t <= (txt.size()/8) ; t = t+11 )
    6. {
    7. txt.insert( t , QString(",0x"));
    8.  
    9. }
    10.  
    11. ui->textEdit->setText(txt);
    12. }
    To copy to clipboard, switch view to plain text mode 

  5. #4
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How to manipulate a text in QTextEdit

    Qt Code:
    1. for (quint32 t = 0 ; t <= (txt.size()/8) ; t = t+11 )
    2. {
    3. txt.insert( t , QString(",0x"));
    4.  
    5. }
    To copy to clipboard, switch view to plain text mode 
    You are comparing the count of characters (stored in "t" and moved by 11 positions on each iteration) with the number of "octets" in the string. The former will always be greater and the loop will end sooner than you expect.
    Look at this simple example with the string "0123456789abcdef" (16 chars):

    iteration 0:
    t=0, string = "0123456789abcdef"
    t <= 2 ? true

    iteration 1:
    t=11, string = ",0x0123456789abcdef"
    t <= (19/8) ? false


    IMHO this would be a lot easier this way:
    Qt Code:
    1. QString txt = ui->textEdit->toPlainText();
    2. while (txt.isEmpty()==false) {
    3. tmp << txt.left(8);
    4. txt.remove(0,8);
    5. }
    6. ui->textEdit->setText(tmp.join(",0x"));
    To copy to clipboard, switch view to plain text mode 

  6. The following user says thank you to stampede for this useful post:

    Ryan111 (29th March 2015)

Similar Threads

  1. how to get the text from QTextEdit
    By qt_user in forum Qt Programming
    Replies: 5
    Last Post: 22nd August 2011, 01:22
  2. QTextEdit::text()
    By hazardpeter in forum Newbie
    Replies: 2
    Last Post: 5th August 2009, 22:13
  3. How to manipulate a thread
    By avis_phoenix in forum Newbie
    Replies: 1
    Last Post: 19th August 2008, 00:34
  4. QTextEdit + paste rich text as plain text only
    By Yong in forum Qt Programming
    Replies: 2
    Last Post: 6th February 2008, 17:45
  5. QTextEdit -> add Text
    By ape in forum Newbie
    Replies: 16
    Last Post: 19th December 2007, 15:59

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.