我在win10上使用QT5.8和Visual Studio 2015来控制串行端口。在消息可视化后,以下最小代码在 Visual Studio 中崩溃(但仅在调试中,发布工作正常(,因此当对象 QList 信息被销毁时,任何人都可以解释原因吗?
#include <iostream>
#include <QtSerialPort/QSerialPortInfo>
void showPorts() {
QList<QSerialPortInfo> infos = QSerialPortInfo::availablePorts();
for (const QSerialPortInfo &info : infos) {
std::cout << " detected port : " << info.portName().toStdString() << std::endl;
}
} // this code CRASHES HERE only in debug !
int main (int argc, char** argv){
std::cout<<"n >>> test serial info <<< nn"<<std::endl;
showPorts();
std::cout << "n >>> Finished, press enter to exit <<< nn" << std::endl;
std::cin.get();
return 0;
}
我已经测试了你的代码,我没有崩溃。
PS: 视窗 10x64, MSVC2015, Qt 5.8.0 32 位