I am not sure what you think this is supposed to do. It isn't assigning anything to the global variable "serial" you already defined.serial : new QSerialPort(this);
It is actually defining a labeled statement (named "serial"), followed by a line of code which creates a new QSerialPort instance that immediately gets turned into a zombie because the return value from the new() operator isn't saved anywhere.
Global variables are considered a bad thing in C++. You should define "serial" as a member variable of the MainWindow class.
Either you open it read / write or you open it read only. This code tries to do both. If opening for read / write succeeds, then the next clause will fail, because it tries to open an already open port using a different mode.if(serial.open(QIODevice::ReadWrite)){
QMessageBox::information(this, "New Box", "Baglandi");
}
if (serial.open(QSerialPort::ReadOnly))
{
Have you looked at the Qt Serial Port examples?
Bookmarks