QSerialPort crashing on QT 5.9.9
-
Hello,
I am trying to write a simple application with serial connection. Somehow it crashes everytime.
I added
QT += serialport
Header:
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include <QSerialPort> QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } QT_END_NAMESPACE class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(QWidget *parent = nullptr); ~MainWindow(); private slots: //void serialReceived(); private: Ui::MainWindow *ui; QSerialPort *serial; }; #endif // MAINWINDOW_H
CPP:
#include "mainwindow.h" #include "ui_mainwindow.h" #include <QDebug> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); serial->setPortName("COM1"); //serial->open(QSerialPort::ReadWrite); //serial->setBaudRate(QSerialPort::Baud115200); //serial->setDataBits(QSerialPort::Data8); //serial->setParity(QSerialPort::NoParity); //serial->setStopBits(QSerialPort::OneStop); //serial->setFlowControl(QSerialPort::NoFlowControl); } MainWindow::~MainWindow() { delete ui; }
As you can see I commented out a lot of code, just to show you that absolutely the simplest tries don't work.
The only error I am getting is:
23:31:58: The program has unexpectedly finished. 23:31:58: The process was ended forcefully.
Does somebody has a clue why it crashes?
INFO: The code above is shortened. There is also a TCP Server and Client running in this application but I do not think it interferes with the SerialPort. Without the SerialPort stuff the programm is running fine.
Further, uncommenting the stuff does not solve the error.
Best Wishes,
Andi -
@ven1ceBeach said in QSerialPort crashing on QT 5.9.9:
serial->setPortName("COM1");
You are using the object serial without it's creation.
create object of serial using new. -
@ven1ceBeach said in QSerialPort crashing on QT 5.9.9:
serial
Please Assign Memory For You
QSerialPort
Objectserial = new QSerialPort(); serial->setPortName("COM1"); //// Your Code ////