【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;
相关推荐
倔强的石头_7 小时前
kingbase备份与恢复实战(二)—— sys_dump库级逻辑备份与恢复(Windows详细步骤)
数据库
肆忆_9 小时前
# 用 5 个问题学懂 C++ 虚函数(入门级)
c++
不想写代码的星星13 小时前
虚函数表:C++ 多态背后的那个男人
c++
jiayou642 天前
KingbaseES 实战:深度解析数据库对象访问权限管理
数据库
端平入洛2 天前
delete又未完全delete
c++
李广坤2 天前
MySQL 大表字段变更实践(改名 + 改类型 + 改长度)
数据库
端平入洛3 天前
auto有时不auto
c++
爱可生开源社区3 天前
2026 年,优秀的 DBA 需要具备哪些素质?
数据库·人工智能·dba
随逸1774 天前
《从零搭建NestJS项目》
数据库·typescript
加号34 天前
windows系统下mysql多源数据库同步部署
数据库·windows·mysql