Solved qt connect crashing app
-
Hi all,
I am going crazy with a simple connect signal and slot. I have this function startDataMonitoring() which is called from another class (GUI class). Stockert70 is not a GUI class but is used as a simple driver for communication with serial port.
void Stockert70::startDataMonitoring()
{
qDebug() << m_pSerialPort->portName();
//connected to serial port
connect(m_pSerialPort, &QSerialPort::readyRead, this, &Stockert70::handleReadyRead);
}When I call this function on a button click I get this error:
"COM6" <--- this is a serial port name read from m_pSerialPort object so it is valid.
Exception thrown at 0x00000000604E2D02 (Qt5Cored.dll) in QStockertSerialPort.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.m_pSerialPort is initialized in another function that is called before this startDataMonitoring() function.
void Stockert70::setSerialPortParameters(QString portName)
{
qDebug() << "Set serial port parameters!";
m_pSerialPort = new QSerialPort();
m_pSerialPort->setPortName(portName);
m_pSerialPort->setBaudRate(QSerialPort::Baud9600);
m_pSerialPort->setDataBits(QSerialPort::Data8);
m_pSerialPort->setParity(QSerialPort::NoParity);
m_pSerialPort->setStopBits(QSerialPort::OneStop);
m_pSerialPort->setFlowControl(QSerialPort::NoFlowControl);
}Any suggestions?
-
Well, you've got a null pointer somewhere. That much is ovbious. OK..."poorly initialize pointer" would be the better description.
And don't do serial comms without flow control. That makes me grind my teeth.
-
@kent-dorfman Yeh but where? m_pSerialPort is not null
-
@zgembo Found out. Stupid mistake. I have creted in .h file a pointe Stockert70 *stockert; and in .cpp I copy and pasted
Stockert70 *stockert = new Stockert70(this);Lost a day on this.