【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;
相关推荐
Small-Young19 小时前
数据库乐观锁深度解析:MySQL、PostgreSQL 实战 + Spring Boot 集成指南
数据库·spring boot·mysql·postgresql·乐观锁·并发控制
浮生若城19 小时前
MySQL 数据库基础
数据库·mysql
xys_67819 小时前
深挖C++:C++入门基础
开发语言·c++
香蕉大香蕉(06敬畏市场)20 小时前
MySQL 单点详解(09)
java·数据库·mysql·面试·八股·大厂实习
瀚高PG实验室20 小时前
瀚高数据库运行日志(错误日志)查看与分析方法
数据库·postgresql·瀚高数据库
snow@li20 小时前
PostgreSQL:PostgreSQL(PG)全景深度梳理
数据库·postgresql
高冷小鱼殿下20 小时前
C 语言指针与输入输出
c++
java_nnnn20 小时前
Spring IoC & DI 从入门到理解:控制反转、依赖注入与 Bean 管理详解
数据库·sql·spring
路溪非溪20 小时前
C++标准库之智能指针
linux·开发语言·c++
瀚高PG实验室21 小时前
HGHAC集群版本升级
数据库·postgresql·瀚高数据库