Results 1 to 4 of 4

Thread: Appended text to QTextEdit

  1. #1
    Join Date
    Feb 2016
    Posts
    16
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Question Appended text to QTextEdit

    I have program to write and read data over QTcpSocket ,when read data I want to appended my socket answer to QTextEdit,I send Multi different Packet,if I send one package each time write data , read data and printout data is true but when appended data to QtextEdit first appended last read data(from Previous package) then if send next package again appended new read data ,how can I fix this??
    I use
    Qt Code:
    1. ui->textEdit->textCursor().insertText(pwr);
    2. ui->textEdit->textCursor().clearSelection();
    3. ui->textEdit->textCursor().deletePreviousChar();
    To copy to clipboard, switch view to plain text mode 
    also,but still first show last appended

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

    Default Re: Appended text to QTextEdit

    Your text is a bit confusing, mixing sending and receiving, showing some code that has nothing to do with appending, etc.

    So you
    - receive data from a QTcpSocket
    - then print it, e.g. using qDebug
    - then append it to a QTextEdit
    correct?

    What happens that you don't want to happen, or what doesn't happen that you expect to happen?
    Can you show the code of the slot you have connected to readyRead()?


    Cheers,
    _

  3. #3
    Join Date
    Feb 2016
    Posts
    16
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Appended text to QTextEdit

    -send frist packet(send true)
    -receive data of first packet from a QTcpSocket(receive true)
    - then print it, e.g. using qDebug(show true)
    - then append data of first packet to a QTextEdit(show true)

    -send second packet (send true)
    -receive data of second packet from a QTcpSocket (receive true)
    - then print it, e.g. using qDebug (show true)
    - then append data of second packet to a QTextEdit(show false) instead of this show append data of first packet to a QTextEdit
    then if I send second packet again
    - append data of second packet to a QTextEdit(show true)


    Qt Code:
    1. connect(_socket, SIGNAL(readyRead()),this, SLOT(readData()));
    2.  
    3. QByteArray QTcp::readData()
    4. {
    5. qDebug() << "reading...";
    6. ReadData= _socket->readAll();
    7. qDebug()<<"readData"<<ReadData.toHex();
    8. return ReadData;
    9. }
    10. QByteArray QTcp::GetTCPData()
    11. {
    12. Readpack.push_back(ReadData);
    13. QByteArray receive_packet = Readpack[Readpack.size() - 1];
    14. Readpack.pop_back();
    15. Readpack.clear();
    16. return receive_packet;
    17. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Appended text to QTextEdit

    Why don't you just append in readData()?
    Returning something in that slot makes little sense, as it is called from a signal.

    The code in GetTCPData() makes even less sense.
    You get the last entry and then clear the whole list/vector?

    Cheers,
    _

Similar Threads

  1. Replies: 1
    Last Post: 7th May 2015, 07:26
  2. Extracting data from appended row
    By JediSpam in forum Qt Programming
    Replies: 2
    Last Post: 15th September 2011, 03:07
  3. QTextEdit + paste rich text as plain text only
    By Yong in forum Qt Programming
    Replies: 2
    Last Post: 6th February 2008, 16:45
  4. QTextEdit -> add Text
    By ape in forum Newbie
    Replies: 16
    Last Post: 19th December 2007, 14:59
  5. Values not being appended in a QList
    By Kapil in forum Newbie
    Replies: 5
    Last Post: 21st April 2006, 10:20

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.