【Qt C++ QSerialPort】QSerialPort fQSerialPortInfo::availablePorts() 执行报错问题解决方案

修正

  • [foreach(const QSerialPortInfo & info, QSerialPortInfo::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);

修复方式

cpp 复制代码
	QStringList portStringLine = {};
	foreach(const QSerialPortInfo & info, QSerialPortInfo::availablePorts())
		portStringLine += info.portName();

改为

cpp 复制代码
	QStringList portStringLine = {};
	QSerialPortInfo* info = new QSerialPortInfo;
	QList<QSerialPortInfo>* PortAllList = new QList<QSerialPortInfo>;
	*PortAllList = QSerialPortInfo::availablePorts();
	foreach(*info, *PortAllList) {
		portStringLine += info->portName();
	}
	delete info;
相关推荐
B站计算机毕业设计之家4 小时前
计算机视觉:pyqt5+yoloV5目标检测平台 python实战 torch 目标识别 大数据项目 目标跟踪(建议收藏)✅
深度学习·qt·opencv·yolo·目标检测·计算机视觉·1024程序员节
程序新视界4 小时前
什么是OLTP ,MySQL是如何支持OLTP的?
数据库·后端·mysql
pen-ai4 小时前
【数据工程】14. Stream Data Processing
数据库·oracle
倔强的石头1064 小时前
【金仓数据库】ksql 指南(三) —— 创建与管理表空间和模式
数据库·金仓数据库
金仓拾光集4 小时前
__金仓数据库平替MongoDB:银行存款系统国产化实践__
数据库·mongodb
流烟默4 小时前
MongoDB入门指南基础篇
数据库·mongodb
金仓拾光集4 小时前
_金仓数据库平替MongoDB实战:制造业生产进度管理的国产化升级之路
数据库·mongodb
南方的狮子先生5 小时前
【数据结构】(C++数据结构)查找算法与排序算法详解
数据结构·c++·学习·算法·排序算法·1024程序员节
熊文豪5 小时前
时序数据库选型指南:从大数据视角看高效存储与分析
大数据·数据库·时序数据库