Solved serialport
-
void MainWindow::on_clickbutn_clicked() { QString qstr; qstr=ui->senderline->text(); QByteArray array; array.append(qstr); qstr=ui->senderline->text(); qDebug() << array; serial->write(array); connect(serial,SIGNAL(readyRead()),this,SLOT(read())); } void MainWindow::read() { // qDebug() << serial->readAll(); QByteArray datas = serial->readAll(); ui->receline->setText(datas); }
this is my code ,my concept is i have to give a input as a text in the line edit(input text) (FIRST LINEEDIT) and i have another line edit(SECOND LINE EDIT) also ,By clicking the pushbutton it shows text in the second line edit what we type in the first line edit.....
And my problem i gave a input as a text in a first line edit and i got a output in a second line edit **but the last letter alone display in the second line edit i want to display whole text **
i dont know what to do ..
i want a rply soon guys........this is my output
-
I won't comment your code, but it looks like it could be cleaned up a lot.
I think your actual problem is, that
MainWindow::read()
is called multiple times when a new chunk of data comes in, but you just display this chunk in the line edit:ui->receline->setText(datas);
That means, ui->receline contains the last chunk you received from the serial port.
i want a rply soon guys........
You probably mean, you would be very thankful if somebody could help you with your problem.
Regards
-
ok sure ,
thanks a lot @aha_1980 -
- Why are you using a
QIODevice
(QSerialPort
?) to send data from one method ofMainWindow
to another? connect
is not unique by default. If you click the button twice the connection will be repeated and the slot will execute 2 times for each signal. either addQt::UniqueConnection
as last argument or, better, move the connect somewhere else (the constructor, maybe)readyRead
is emitted when some data is available, there's no guarantee all the data can be read- use streams to safely serialise data:
const QString qstr=ui->senderline->text(); QDataStream serialWriteStream(serial); serialWriteStream<< qstr;
QDataStream serialReadStream(serial); serialReadStream.startTransaction(); QString receivedText; serialReadStream >> receivedText; if(serialReadStream.commitTransaction()) ui->receline->setText(receivedText);
- Why are you using a
-
thanks @VRonin