简体   繁体   English

通过QTest将无效的参数传递给C运行时函数

[英]Invalid parameter passed to C runtime function with QTest

I am developing a Qt project with Qt creator, all works fine, but when i came to the unit testing part using QTest, after compilation I get the error "Invalid parameter passed to C run-time function". 我正在用Qt创建器开发一个Qt项目,一切正常,但是当我使用QTest进入单元测试部分时,编译后出现错误“将无效参数传递给C运行时函数”。

Can anyone help me to find the source of the problem? 谁能帮助我找到问题的根源? Is it due to the use of cstdio functions or has it something to do with the .pro configuration? 是由于使用cstdio函数还是与.pro配置有关?

This is a test method I implemented and did not work: 这是我实施的测试方法,无法正常工作:

void TestFichier::testLoad()
{
    Fichier a;
    a.load("input.txt");
    FILE *f=fopen("input.txt","rb");
    int c;
    int i,*tab=a.getHexValues();
    for (i=0;i<3;i++)
        c=fgetc(f);
    fclose(f);
    QCOMPARE(tab[2],c);
}

Fichier is a class I created with a method load . Fichier是我使用方法load创建的类。

MSDN fgetc documentation states: MSDN fgetc文档指出:

If [the parameter] stream is NULL, fgetc and fgetwc invoke the invalid parameter handler, as described in Parameter Validation . 如果[parameter]流为NULL,则fgetc和fgetwc调用无效的参数处理程序,如Parameter Validation中所述

So you should check if fopen returns NULL , and in that case, find the type of error with errno . 因此,您应该检查fopen返回NULL ,在这种情况下,请使用errno查找错误的类型。

Probably, your problem is that you make some errors while working with dynamical memory. 可能是您的问题是在使用动态内存时会出错。 For example, you can use pointers to unallocated memory, or so. 例如,您可以使用指向未分配内存的指针等等。 Check your code at getHexValues() method. getHexValues()方法中检查代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM