【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;
相关推荐
微学AI27 分钟前
内网穿透的应用-突破局域网束缚,MongoDB 远程访问使用cpolar原来可以这么简单
数据库·mongodb
大锦终2 小时前
【MySQL】内置函数
数据库·mysql
猿小喵2 小时前
索引优化-MySQL性能优化
数据库·mysql·性能优化
n***F8753 小时前
修改表字段属性,SQL总结
java·数据库·sql
颜*鸣&空3 小时前
QT程序实现串口通信案例
开发语言·qt
Main. 244 小时前
从0到1学习Qt -- 常见控件之显示类控件
qt·学习
q***78375 小时前
mysql表添加索引
数据库·mysql
招摇的一半月亮5 小时前
P2242 公路维修问题
数据结构·c++·算法
翔云1234565 小时前
MySQL 机器重启后,gtid_executed 是如何初始化的
数据库·mysql·adb