Results 1 to 4 of 4

Thread: How to manipulate a text in QTextEdit

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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 

  2. 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, 00:22
  2. QTextEdit::text()
    By hazardpeter in forum Newbie
    Replies: 2
    Last Post: 5th August 2009, 21:13
  3. How to manipulate a thread
    By avis_phoenix in forum Newbie
    Replies: 1
    Last Post: 18th August 2008, 23:34
  4. QTextEdit + paste rich text as plain text only
    By Yong in forum Qt Programming
    Replies: 2
    Last Post: 6th February 2008, 16:45
  5. QTextEdit -> add Text
    By ape in forum Newbie
    Replies: 16
    Last Post: 19th December 2007, 14: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.