QT Critical error detected c0000374

created at 07-30-2021 views: 28

When using QT to write GraphicsView, when running the program to add Item, an error was reported for no reason. The debug debugging also jumped to the QT source code. It was not the same position error, and some errors were reported at the new position. The error message is "Critical error detected c0000374", and the searched articles are all insufficient memory, out of bounds, etc., and there are problems with smart pointers, but I have none of the above problems.

When the memory is sufficient, new can report an error, which should not have much to do with the memory. In addition, when the code does not change or some changes have no effect, the error is not in the same place. I think it can rule out insufficient memory, out of bounds, and so on.

1. But most of the program bugs are related to pointers, so I annotated the pointer variables in my class. As a result, there was no problem at all. Moreover, my pointers were only defined and it was useless, even the assignment of nullptr operations. No, it's really weird. The following example 1 code

//example 1
//.h file
class A{
int a;
int b;
int *p;//If you comment, the operation will be no problem. If you do not comment, it will pop up, and the error message "Critical error detected c0000374" will be printed.
int c;
...
int z;
}

//.cpp file
A::A:a(0),b(1),c(2){}

2. I only write the pointer variable after all the variables. I changed the order and there was no problem with the operation. I thought that would solve the problem. As a result, I just assigned nullptr to this variable and it jumped again. The following example 2 code

//Example 2
//.h file
class A{
int a;
int b;
int c;
...
int z;
int *p;
}

//.cpp file
A::A:a(0),b(1),c(2),
p(nullptr)//The comment can be run, and the operation will jump without comment, the error message "Critical error detected c0000374" is printed
{}

3. At first, I suspected that it was a problem with the variable type, but it didn’t work if I changed it to another type later. I wondered if it was because there was a problem with the data in the .cpp file, so I created a new .h and .cpp file and planned to rewrite the code of the original file. As a result, only the code similar to the following was written, that is, only the original .h file was written Variable definitions and construction functions, nothing else was written, and it runs without problems. Then I retryed the problematic .h.cpp file and found that it can also run without any problems. The code has not been changed at all. I tried to change it to what it looked like before, and the result was no problem. This process just rebuilds the source code and regenerates any files generated by the previous compilation. Because after adding a new file in Qt, you need to re-execute qmake->build/run/rebuild (or clear->build/run/rebuild), this process will re-compile the previously generated .obj, ui_xxx and other files according to the current The code is generated. So I suspect that there is a problem with the related files generated by the previous compilation, which caused the "Critical error detected c0000374" problem.

//
//.h file
class A{
int a;
int b;
int c;
...
int z;
int *p;
}

//.cpp file
A::A:a(0),b(1),c(2),
p(nullptr)
{}

According to the above guess, the solutions that can be tried to eliminate the problems of memory, cross-border and smart pointers: 

  1. Clear all the files generated by the previous compilation, and recompile all the contents again.
  2. Retype the problematic .h.cpp, it is best not to copy, to avoid file data problems. Copying may copy the previously problematic data together.
  3. Do 2 first, then 1
created at:07-30-2021
edited at: 07-30-2021: