QDebug() prevents from crash?



  • Hello,

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

    My program crashes and when I insert a @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:

    @
    for (int i = 0; i < knownPivotFeatures.size(); i++) {
    // qDebug() << "foo";
    if(knownPivotFeatures[i]){
    qDeleteAll(knownPivotFeatures[i]);
    } else {
    QDEBUG<<"Hashmap does not exist";
    }
    }
    @
    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



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



  • @Andre Could you give advice for such software?



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



  • Not without you telling us what platform you're on. On linux, you could look into "valgrind":http://valgrind.org/.



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



  • 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.



  • 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.



  • [quote author="Smar" date="1303137713"]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.[/quote]

    This explanation is sufficient for me, thank you :)

    [quote author="Smar" date="1303137713"]
    Valgrind would tell exact reason for that, just use it, since you’re only one who actually has your code.
    [/quote]
    I´m using Windows and am to lazy to find an equivalent shy


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.