PDA

View Full Version : Appended text to QTextEdit



isan
1st May 2016, 14:32
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

ui->textEdit->textCursor().insertText(pwr);
ui->textEdit->textCursor().clearSelection();
ui->textEdit->textCursor().deletePreviousChar();
also,but still first show last appended

anda_skoa
1st May 2016, 15:39
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,
_

isan
1st May 2016, 16:34
-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)



connect(_socket, SIGNAL(readyRead()),this, SLOT(readData()));

QByteArray QTcp::readData()
{
qDebug() << "reading...";
ReadData= _socket->readAll();
qDebug()<<"readData"<<ReadData.toHex();
return ReadData;
}
QByteArray QTcp::GetTCPData()
{
Readpack.push_back(ReadData);
QByteArray receive_packet = Readpack[Readpack.size() - 1];
Readpack.pop_back();
Readpack.clear();
return receive_packet;
}

anda_skoa
1st May 2016, 21:32
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,
_