首页| 论坛| 消息

标题:采用C++Interop方式调用QT代码时,再CLR代码中调用QString.split("")报错
作者:today_yu
日期:2023-10-19 10:09
内容:

用QT做了一个类库,.net端调用。想采用C++interop方式,用托管C++(CLR)类中调用QT中的类方法,结果出现“System.BadImageFormatException:“未能加载文件或程序集“QtTestIntrop, Version"错误。 我于是把QT端的代码简化,直至发现 当 调用 QString的split方法时,会出现这个错误,把这句话屏蔽掉,就不出错。
最后,我直接在 托管C++ CLR端写
“int testclrwarpper::exportreport()
{
QString aa = "aaaaaa";
aa = aa.append("aaa");
QStringList ab = aa.split(',');
return 0;
}
” 不出意外,也出现 “System.BadImageFormatException:“未能加载文件或程序集“QtTestIntrop, Version"错误。
请教各位大牛,是否知道是什么原因。


#1 [xlinger 10-19 14:41]
https://stackoverflow.com/questions/27281180/unhandled-exception-system-badimageformatexception-could-not-load-file-or-asse
#2 回 xlinger 的帖子 [today_yu 10-19 17:08]
xlinger:https://stackoverflow.com/questions/27281180/unhandled-exception-system-badimageformatexception-could-not-load-file-or-asse (2023-10-19 14:41) 
首先,谢谢楼主提供相关的信息;我看了下帖子,里面应该是提问者最后找到原因是缺少了Qt的库。我按此方法查找了我的dll的依赖库:
第一层:
Qt5Core.dll
VCRUNTIME140.dll
api-ms-win-crt-runtime-l1-1-0.dll
KERNEL32.dll
mscoree.dll
其中只有Qt5Core.dll是qt库,其他是系统的;我继续查找了Qt5Core,其依赖库如下:我查找了,都有。然后就没有思路了。
MPR.dll
USERENV.dll
VERSION.dll
NETAPI32.dll
WS2_32.dll
ADVAPI32.dll
KERNEL32.dll
ole32.dll
SHELL32.dll
USER32.dll
WINMM.dll
MSVCP140.dll
MSVCP140_1.dll
VCRUNTIME140.dll
VCRUNTIME140_1.dll
api-ms-win-crt-runtime-l1-1-0.dll
api-ms-win-crt-heap-l1-1-0.dll
api-ms-win-crt-environment-l1-1-0.dll
api-ms-win-crt-stdio-l1-1-0.dll
api-ms-win-crt-time-l1-1-0.dll
api-ms-win-crt-math-l1-1-0.dll
api-ms-win-crt-string-l1-1-0.dll
api-ms-win-crt-utility-l1-1-0.dll
api-ms-win-crt-convert-l1-1-0.dll
api-ms-win-crt-filesystem-l1-1-0.dll
#3 [blueman8888 11-02 16:23]
建议不要在clr运行时里面直接调用qt的资源,因为qt的运行时与clr的运行时是不兼容的。qt的信号槽机制的运行时跟这个clr的运行时是有区别的。最好将qt写的dll,在api暴露到clr调用时,采用标准C++类型,QString用std::string代替,这样就不会出现问题。直接在clr里面是没法运行qt的一些东西的。

回复 发表
主题 版块