我在窗户上,qt 4.7。我的部分代码从打开的文件中获取一个文件*,该文件可供系统的另一部分(旧版,C)读取。我按如下方式打开一个QTextStream:
// file currently opened (readonly), and partially read
FILE *infile = function_to_get_file_pointer();
QTextStream is(infile, QIODevice::ReadOnly);
第二行在发布模式下生成时崩溃,但在调试中很好。我可以逐步浏览调试版本,并查看由QFile在内部打开的QTextStream。在崩溃时,在释放模式下,我设法从windows调用堆栈中获得的最多信息如下:
ntdll.dll!77450226()
[Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll]
ntdll.dll!77450142()
msvcr80.dll!_lock_file(_iobuf * pf=0x71962148) Line 241 + 0xa bytes C
msvcr80.dll!_ftelli64(_iobuf * stream=0x71962148) Line 51 + 0x8 bytes C
QtCore4.dll!6708b87d()
QtCore4.dll!67099294()
QtCore4.dll!6713d491()
这可能是一只红鲱鱼,但看起来好像有什么地方出了问题,试图锁定文件。在此之前,我已经为我的代码启用了调试输出,所以我知道是QTextStream创建导致了问题。欢迎任何建议!
经过进一步的研究,我发现这个文件,尽管ASCII,最初是用"rb“打开的,目的是阻止win32 CRT将行尾从\r\n转换到\r \n,我认为这会使Qt混淆,所以修改了fopen,只使用"r”。然后,下面链接到这里的注释显示文件*应该以二进制模式打开,例如"rb",所以这不是问题。
尝试下面的tezrigs建议,文件*上的freopen给出了以下内容:
msvcr100.dll!_crt_debugger_hook(int _Reserved=8633404) Line 65 C
msvcr100.dll!_call_reportfault(int nDbgHookCode=2, unsigned long dwExceptionCode=3221226519, unsigned long dwExceptionFlags=1) Line 167 + 0x6 bytes C++
msvcr100.dll!_invoke_watson(const wchar_t * pszExpression=0x00000000, const wchar_t * pszFunction=0x00000000, const wchar_t * pszFile=0x00000000, unsigned int nLine=0, unsigned int pReserved=8633376) Line 155 + 0xf bytes C++
msvcr100.dll!_invalid_parameter(const wchar_t * pszExpression=0x00000000, const wchar_t * pszFunction=0x00000000, const wchar_t * pszFile=0x00000000, unsigned int nLine=0, unsigned int pReserved=0) Line 110 + 0x14 bytes C++
msvcr100.dll!_invalid_parameter_noinfo() Line 121 + 0xc bytes C++
msvcr100.dll!_freopen_helper(_iobuf * * pfile=0x0083bc3c, const char * filename=0x00000000, const char * mode=0x013ee350, _iobuf * str=0x71962148, int shflag=64) Line 31 + 0x1f bytes C
msvcr100.dll!freopen(const char * filename=0x00000000, const char * mode=0x013ee350, _iobuf * str=0x71962148) Line 111 C
传递给_call_report_fault的异常代码是0x0000417 -致命错误:未知软件异常,帮助不大。
OK:更多细节,以及一些可自我包含的可复制代码(myfile.txt必须超过1000个字符长):
#include <QtCore/QCoreApplication>
#include "qtextstream.h"
#include <iostream>
int main(int argc, char *argv[])
{
// QCoreApplication a(argc, argv);
std::cin.get();
FILE *myfile = fopen("myfile.txt", "rb");
int c;
for(int i=0; i < 1000; i++)
c = getc(myfile);
fflush(myfile);
long pos = ftell(myfile);
QTextStream is(myfile, QIODevice::ReadOnly);
while(!is.atEnd())
{
QString in_line = is.readLine();
std::cout << in_line.toStdString();
}
fseek(myfile, pos, SEEK_SET);
fclose(myfile);
return 0;
}
在发布模式中,以下所有内容:
这样,如果我在visual studio之外运行,就可以附加调试器。如果我在视频演播室外面运行,它就会崩溃。如果我把它附加到它的外部visual中,它就会在构建QTextStream时崩溃。如果我在visual studio中使用shift-F5启动它(即运行在调试器之外),它会将文件的内容写入显示器。同样,当在调试器下运行时,它也可以正常工作。
这要归功于dlls。我有一组本地编译的dll(用MSVC2010创建),并使用它们来替换主产品中的dll,解决了这个问题。测试代码也是如此。发布代码使用使用2005年编译的Qt,使用msvcr80。
发布于 2016-05-10 16:50:34
所有的信用@卡斯滕库普-欢迎张贴您的答案在这里。问题是由于Qt使用msvcr80.dll,而应用程序的其余部分是使用visual studio 2010编译的,因此使用msvcr100.dll。
这个链接很好地解释了混合visual studio版本的危险。
https://stackoverflow.com/questions/37136084
复制相似问题