Qt项目,引用了QtXlsx,准备运行,提示报错:

QtXlsx: No such file or directory

QtXlsx: no such file or directory_Qt

 奇怪。按理说,安装QtXlsx的三个步骤都已经执行成功了:

qmake
make
make install

把生成的so库文件拷贝到相关目录也是无效。

换个思路,检查一下qmake:

QtXlsx: no such file or directory_运维_02

 发现一点问题:当前qmake使用的是Qt5.12.8, 可能是银河麒麟系统自带的,也可能是我曾经安装过的。但是现在安装的是Qt5.9.8,怎么qmake还在使用5.12.8?

研究了一下qmake的问题,猜测QtXlsx无法识别很可能是由于qmake引用Qt版本问题导致的:

引用QtXlsx库的主程序用的Kit是Qt5.9.8,但是build QtXlsx时用的是系统默认的qmake也就是5.12.8的Qt,这里面估计有些冲突。现在的目标是要让系统默认使用5.9.8的qmake。

折腾一番,参考一篇早期的文章,找到了解决方案:

qmake:Could not find command-not-found database_could not find command-not-found database run sudo_小鹰信息技术服务部的博客

找到如下文件:

/usr/lib/x86_64-linux-gnu/qt-default/qtchooser/default.conf

QtXlsx: no such file or directory_信息技术_03

 打开观察文件内容:

/usr/lib/qt5/bin
/usr/lib/x86_64-linux-gnu

其中第一行的bin目录下面,是有qmake程序的,这是什么时候安装的?搞不清了。

把第一行替换成新安装的Qt 5.9.8中的qmake目录:

/home/zhouyingge1104/Qt5.9.8/5.9.8/gcc_64/bin
/usr/lib/x86_64-linux-gnu

重新测试qmake:

QtXlsx: no such file or directory_linux_04

 成功,已经切换到了5.9.8的qmake。

然后重新运行QtXlsx编译的三个步骤:

qmake
make
make install

回到QtCreator中,QtXlsx的引用<>不再报错,正常了:

QtXlsx: no such file or directory_linux_05

至此,问题解决,这个周日很充实!