Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QDebug() prevents from crash?
QtWS25 Last Chance

QDebug() prevents from crash?

Scheduled Pinned Locked Moved General and Desktop
9 Posts 5 Posters 5.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    justMe
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • S Offline
        S Offline
        secretNinja
        wrote on last edited by
        #3

        @Andre Could you give advice for such software?

        1 Reply Last reply
        0
        • JohanSoloJ Offline
          JohanSoloJ Offline
          JohanSolo
          wrote on last edited by
          #4

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

          `They did not know it was impossible, so they did it.'
          -- Mark Twain

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • S Offline
              S Offline
              secretNinja
              wrote on last edited by
              #6

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

              1 Reply Last reply
              0
              • J Offline
                J Offline
                justMe
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  Smar
                  wrote on last edited by
                  #8

                  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.

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    justMe
                    wrote on last edited by
                    #9

                    [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

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved