QT5.15.2使用QXlsx读取Excel文件后退出程序时程序异常结束

embedded/2024/10/18 20:20:58/

QT5.15.2使用QXlsx读取Excel文件后退出程序时程序异常结束

这是一个困扰了我很久的问题,今天终于解决啦。

异常场景

我的情况是只要用了QXlsx去操作Excel文件后,在关闭程序时无法正常退出程序,会卡住,过一会后在QT的IDE上显示程序异常结束。

解决方法

主要原因在于QXlsx源码的xlsxcellreference.cpp中,
我们只需要找到void CellReference::init(const QString &cell_str)方法,把static thread_local QRegularExpression re(QStringLiteral("^\\$?([A-Z]{1,3})\\$?(\\d+)$"));thread_local修饰删掉,或者改成这样:

void CellReference::init(const QString &cell_str)
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)static QRegularExpression re(QStringLiteral("^\\$?([A-Z]{1,3})\\$?(\\d+)$"));QRegularExpressionMatch match = re.match(cell_str);if (match.hasMatch()){const QString col_str = match.captured(1);const QString row_str = match.captured(2);_row = row_str.toInt();_column = col_from_name(col_str);}
#elseQRegExp re(QLatin1String("^\\$?([A-Z]{1,3})\\$?(\\d+)$"));if (re.indexIn(cell_str) != -1){const QString col_str = re.cap(1);const QString row_str = re.cap(2);_row = row_str.toInt();_column = col_from_name(col_str);}
#endif
}

然后再找到QString col_to_name(int col_num)方法,同样的把static thread_local QMap<int, QString> col_cache;thread_local修饰删掉:

QString col_to_name(int col_num)
{static QMap<int, QString> col_cache;auto it = col_cache.find(col_num);if (it == col_cache.end()) {QString col_str;int remainder;while (col_num) {remainder = col_num % 26;if (remainder == 0)remainder = 26;col_str.prepend(QChar('A' + remainder - 1));col_num = (col_num - 1) / 26;}it = col_cache.insert(col_num, col_str);}return it.value();
}

保存后重新编译就行了,这样就能正常退出程序了

参考资料

其实QXlsx已经修复了这个问题,是因为我那个版本还存在这个问题而已,github的issues中就有了
https://github.com/QtExcel/QXlsx/issues/156
https://github.com/QtExcel/QXlsx/issues/153


http://www.ppmy.cn/embedded/109303.html

相关文章

Opencv中的直方图(3)直方图比较函数compareHist()的使用

操作系统&#xff1a;ubuntu22.04 OpenCV版本&#xff1a;OpenCV4.9 IDE:Visual Studio Code 编程语言&#xff1a;C11 算法描述 比较两个直方图。 函数 cv::compareHist 使用指定的方法比较两个密集或两个稀疏直方图。 该函数返回 d ( H 1 , H 2 ) d(H_1, H_2) d(H1​,H2​…

Qt-常用控件(3)-多元素控件、容器类控件和布局管理器

1. 多元素控件 Qt 中提供的多元素控件有: QListWidgetQListViewQTableWidgetQTableViewQTreeWidgetQTreeView xxWidget 和 xxView 之间的区别&#xff0c;以 QTableWidget 和 QTableView 为例. QTableView 是基于 MVC 设计的控件.QTableView 自身不持有数据,使用 QTableView 的…

导入word模板的数据到DB,偏自学,可自改套用

GetMapping("/importTestPeople")public void importTestPeople(RequestParam("file") MultipartFile multipartFile) throws IOException {InputStream inputStream null;File file null;try {// 创建临时文件file File.createTempFile("temp&quo…

如何用python远程测试连接redis服务器

前提条件 A&#xff1a;操作机&#xff08;操作系统不限&#xff09; B&#xff1a;装有redis的服务器&#xff08;linux系统&#xff09; 而且需要配置redis服务器允许外部连接。这个一般是在redis的配置文件里修改相关选项。redis.conf或者6379.conf就是redis的配置文件 b…

RedissonClient 分布式队列工具类

注意&#xff1a;轻量级队列可以使用工具类&#xff0c;重量级数据量 请使用 MQ 本文章基于redis使用redisson客户端实现轻量级队列&#xff0c;以及代码、执行结果演示 一、常见队列了解 普通队列&#xff1a;先进先出&#xff08;FIFO&#xff09;&#xff0c;只能在一端添…

线性代数基础

Base 对于矩阵 A&#xff0c;对齐做 SVD 分解&#xff0c;即 U Σ V s v d ( A ) U\Sigma V svd(A) UΣVsvd(A). 其中 U 为 A A T AA^T AAT的特征向量&#xff0c;V 为 A T A A^TA ATA的特征向量。 Σ \Sigma Σ 的对角元素为降序排序的特征值。显然&#xff0c;U、V矩阵…

密码学---常见的其他密码

✨费纳姆密码&#xff1a;加解密都需要密钥&#xff0c;以二进制形式表示的密码。&#xff08;密钥多是一次性的&#xff0c;称位一次性密码本&#xff09; 加密过程&#xff1a; char_num {A: 1000001, B: 1000010, C: 1000011, D: 1000100,E: 1000101, F: 1000110, G: 100…

MFC终止线程实例

本程序基于前期我的博客文章《MFC用信号灯模拟工控机数字量输入信号实时采集实例&#xff08;源码下载》 1、在主界面添加一个启动线程按钮&#xff0c;一个终止线程按钮。 2、在TheradDlg.h中相关代码 class CTheradDlg : public CDialog { // Construction public: ... C…