我在win10上使用QT5.8和visual studio 2015来控制串口。以下最小代码在可视化消息后在 Visual Studio 中崩溃(但仅在调试中,发布工作正常),所以当对象 QList infos 被破坏时,任何人都可以解释为什么?
#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 <<< \n\n"<<std::endl;
showPorts();
std::cout << "\n >>> Finished, press enter to exit <<< \n\n" << std::endl;
std::cin.get();
return 0;
}