0

我在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;
}
4

1 回答 1

0

我已经测试了你的代码,我没有崩溃。

PS:Windows 10x64、MSVC2015、Qt 5.8.0 32 位

于 2017-05-23T14:46:36.097 回答