【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;
相关推荐
此生只爱蛋10 分钟前
【Redis】主从复制
数据库·redis
Zach_yuan12 分钟前
深入浅出 JSONCpp
linux·服务器·网络·c++
寻寻觅觅☆28 分钟前
东华OJ-基础题-104-A == B ?(C++)
开发语言·c++
马猴烧酒.29 分钟前
【面试八股|JAVA多线程】JAVA多线程常考面试题详解
java·服务器·数据库
杨了个杨898234 分钟前
memcached部署
qt·websocket·memcached
lightqjx39 分钟前
【C++】unordered系列的封装
开发语言·c++·stl·unordered系列
天天爱吃肉82181 小时前
跟着创意天才周杰伦学新能源汽车研发测试!3年从工程师到领域专家的成长秘籍!
数据库·python·算法·分类·汽车
大巨头1 小时前
sql2008 数据库分页语句
数据库
m0_715575341 小时前
使用PyTorch构建你的第一个神经网络
jvm·数据库·python
阿猿收手吧!1 小时前
【C++】string_view:高效字符串处理指南
开发语言·c++