QSerialPort causes "The program has unexpectedly finished" in QT

80 Views Asked by At

If I run this constructor

USB::USB(){
    serialPort = new QSerialPort();
    serialPortInfo = new QSerialPortInfo();
}

From this class

#include <QSerialPort>
#include <QSerialPortInfo>

class USB {
public:
    USB();
private:
    QSerialPort* serialPort;
    QSerialPortInfo* serialPortInfo;
};

Then I got the error

The program has unexpectedly finished.

If I comment the code

USB::USB(){
    //serialPort = new QSerialPort();
    //serialPortInfo = new QSerialPortInfo();
}

Then I get no errors at all. Why does this happens? I have missed something?

I'm running QT5 at Windows 10.

This gives no errors. Getting information about the COM ports works.

USB::USB(QSerialPort* serialPort, const QSerialPortInfo& serialPortInfo){
    this->serialPort = serialPort;
    this->serialPortInfo = serialPortInfo;
}
0

There are 0 best solutions below