April 15, 2011

justMe justMe
Lab Rat
10 posts

qDebug() prevents from crash?

 

Hello,

I´ve got a strange problem -at least for me :D

My program crashes and when I insert a

  1. qDegug() << "foo";
,it runs.
Unfortunately, I was not able to write a minimum example, that compiles and shows the same problem.
So just here a few lines from my code, to make you understand my problem:

  1.     for (int i = 0; i < knownPivotFeatures.size(); i++) {
  2. //    qDebug() << "foo";
  3.       if(knownPivotFeatures[i]){
  4.         qDeleteAll(*knownPivotFeatures[i]);
  5.       } else {
  6.         QDEBUG<<"Hashmap does not exist";
  7.       }
  8.     }

where knownPivotFeatures is a QList<QHash<QUuid, MyClass const*>*>.

(Another issue is, that the compiler seems to change the order. I added another qDebug() << “bar”; to the Destructor of MyClass. And first, the “foo“s (more than one ;)) are printed and finally the “bar“s.)

I´m afraid, that the source of my problem(s) is somewhere completely else, but probably, you have an idea, what kind of problem I should look for?

Thank you in advance,

Maria

8 replies

April 15, 2011

Andre Andre
Robot Herder
6295 posts

Try running your program through a detector for memory problems. Or just remove the debug statement and fix the actual cause of the crash.

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

April 15, 2011

secretNinja secretNinja
Lab Rat
141 posts

@Andre Could you give advice for such software?

April 15, 2011

Johan Solo Johan Solo
Ant Farmer
120 posts

If you’re on linux then valgrind will do the job.

 Signature 

Linux : you can find worse, but it’s more expensive.

April 15, 2011

Andre Andre
Robot Herder
6295 posts

Not without you telling us what platform you’re on. On linux, you could look into valgrind [valgrind.org].

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

April 15, 2011

secretNinja secretNinja
Lab Rat
141 posts

I’m using both Windows and Linux … two votes for valgrind is more than enough. Thank you.
Sorry for almost off-topic messages.

April 18, 2011

justMe justMe
Lab Rat
10 posts

Hello everyone!

I fixed my memory leak and really: The program did not crash any more (it did not crash because the RAM was full, it crashed for any other still unknown reason).

But I´m still curious: How can it be, that the single line “qDebug() << “foo”; prevents my program from crashing?

And is it the compiler optimization, that the “foo“s and “bar“s are not mixed, when I add the “bar” to the destructor?

Thanks a lot,

Maria.

April 18, 2011

Smar Smar
Lab Rat
269 posts

In theory, qDebug() takes some buffer and does something for it that would otherwise make the faulty line address memory that is not usually available. Valgrind would tell exact reason for that, just use it, since you’re only one who actually has your code.

April 19, 2011

justMe justMe
Lab Rat
10 posts
Smar wrote:
In theory, qDebug() takes some buffer and does something for it that would otherwise make the faulty line address memory that is not usually available.

This explanation is sufficient for me, thank you :)

Smar wrote:

Valgrind would tell exact reason for that, just use it, since you’re only one who actually has your code.

I´m using Windows and am to lazy to find an equivalent shy

 
  ‹‹ QComboBox - strange behavior after clear()      QTableWidget - Word Wrap ››

You must log in to post a reply. Not a member yet? Register here!