我在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 <<< \n\n"<<std::endl;
showPorts();
std::cout << "\n >>> Finished, press enter to exit <<< \n\n" << std::endl;
std::cin.get();
return 0;
}发布于 2017-05-23 22:46:36
我已经测试了你的代码,我没有崩溃。
PS: Windows 10x64、MSVC2015、Qt 5.8.0 32位
https://stackoverflow.com/questions/44130828
复制相似问题