【Qt C++ QSerialPort】QSerialPort fQSerialPortInfo::availablePorts() 执行报错问题解决方案
修正
- foreach(const QSerialPortInfo & info, QSerialPortInfo::availablePorts())报错修复
- 修复方式
foreach(const QSerialPortInfo & info, QSerialPortInfo::availablePorts())报错修复
debug模式 foreach(const QSerialPortInfo & info, QSerialPortInfo::availablePorts())
portStringLine += info.portName();堆栈报错位置
template
Q_OUTOFLINE_TEMPLATE QList::~QList()
{
if (!d->ref.deref())
dealloc(d);
}
template
Q_OUTOFLINE_TEMPLATE void QList::dealloc(QListData::Data *data)
{
node_destruct(reinterpret_cast<Node *>(data->array + data->begin),
reinterpret_cast<Node *>(data->array + data->end));
QListData::dispose(data);
}
template
Q_INLINE_TEMPLATE void QList::node_destruct(Node *from, Node to)
{
if (QTypeInfo::isLarge || QTypeInfo::isStatic)
while(from != to) --to, delete reinterpret_cast<T>(to->v);
修复方式
QStringList portStringLine = {};foreach(const QSerialPortInfo & info, QSerialPortInfo::availablePorts())portStringLine += info.portName();
改为
QStringList portStringLine = {};QSerialPortInfo* info = new QSerialPortInfo;QList<QSerialPortInfo>* PortAllList = new QList<QSerialPortInfo>;*PortAllList = QSerialPortInfo::availablePorts();foreach(*info, *PortAllList) {portStringLine += info->portName();}delete info;
