Solved small console program keeps crashing for some unknown reason
-
@jsulm Thanks I see now that it crashes on line 189 of Qatomic_x86.cpp. What does this mean? I also see that the processDirectory and getChecksum functions has no issue however this crash happens before getDuplicateList runs?
the reason I use pointers is that I get an error message when trying to pass a QFile as argument to generateChecksumhere's a link to my code if it helps to see it in QTCreator:
-
@Dn588 What error do you get if you pass QFile to generateChecksum?
It should be like this:QByteArray FileChecker::generateChecksum(QFile& file) // Change QFile* to QFile& { ... }
This are C++ basics.
And again if you want to use pointer then you have to create an instance using new and later delete it. But in your case there is really no need for pointers - just fix your interface to pass QFile as reference. And even if you want to pass a pointer you can do so:QFile file; ... generateChecksum(&file);
I'm quite sure the problem is not in QAtomic. You should take a look at the call stack who is calling QAtomic?
At which line in your code does it crash? -
@jsulm I put a breakpoint at the end of generateChecksum and the program gets there with no issues so i'm guessing the processDirectory and generateChecksum functions are ok? So the crash happens after generateChecksum but i'm not exactly sure where. Where can I view the calling stack?
I get the following error when debugging
"The inferior stopped because it received a signal from the operating system
signal name: SIGSEGV
signal meaning: segmentation fault
"Yes sorry I should have passed by reference from the start. Seems like 6 month's break from C++ made me forget quite a lot...
Thanks again for all your help/patience
-
Fix like this to not to crash:
QByteArray FileChecker::generateChecksum(QFile* file) { if(file->open(QIODevice::ReadOnly)) { QCryptographicHash cHash(QCryptographicHash::Md5); cHash.addData(file->readAll()); QByteArray checksum = cHash.result(); return checksum; } // This line was missing, so you did not return a valid QByteArray instance if the if condition was false! return QByteArray(); }
-
@jsulm Thanks that worked!. However now it seems like the file i'm passing to generateChecksum has no fileName? I get 12 errors in the terminal saying " QFSFileEngine::open no file name specified". the directory I am entering has 4 .dat files which consists of 2 groups of 2 duplicate files. Any idea what is happening here? Also where can I view the calling stack in future if I have a crash like before?
-
@Dn588
Call stack -
@Dn588 Debug your application step by step and see what happens and what is wrong.
-
@Dn588 The problem is: you pass only the file name without the directory. So your application tries to open that file in current directory. You can see it easily if you debug.
-
Thanks @jsulm Will do:) is therre a way to view the contents of a variable while debugging? I google'd that error and it seems like it happens when the QFile is initialized with a name so I used QFile->setFileName(fileList.at(i)) but still no luck... Sorry for all the excessive questions... i'm writing two exams tomorrow and on mon and have this program to finish before mon to get an internship interview so stressing a bit...
-
@Dn588 said:
contents of a variable while debugging?
See picture. its on right side. showing Name / Value / type
and "this" variable. -
-
@jsulm Sorry I see that's possible in the call stack. Sorry I have an eye problem and as a result only have 4% vision so missed it the first time...
-