@Apeksha Firstly, most serial communication is terminated with a courage return or a new line or both.
For example
QByteArray ba("Hello\r\n");
serial.write(ba);
The serial device might be expecting an "end of message" signal, which is usually a courage return and a new line.
On the second note, try and create a separate object for your serial communication class, like below :
SerialData::SerialData(QString port, QObject *parent) :
QObject(parent)
{
mPort = new QSerialPort(this);
connect(mPort, SIGNAL(readyRead()), SLOT(readData()));
mPort->setPortName(port);
mPort->setBaudRate(QSerialPort::Baud115200);
mPort->setDataBits(QSerialPort::Data8);
mPort->setParity(QSerialPort::NoParity);
mPort->setStopBits(QSerialPort::OneStop);
mPort->setFlowControl(QSerialPort::NoFlowControl);
if(mPort->open(QIODevice::ReadWrite)){
mPort->setTextModeEnabled(true);
mPort->write("Hello\r\n");
qDebug() << "Port open at " << mPort->portName();
}
else{
qDebug() << "Failed to open tty port " << mPort->portName();
}
}
void SerialData::readData()
{
QString data = mPort->readAll();
qDebug() << "Serial data IN : " << data;
}