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. Q_ASSERT handler ?
QtWS25 Last Chance

Q_ASSERT handler ?

Scheduled Pinned Locked Moved Solved General and Desktop
qasserthandlerruntime
6 Posts 3 Posters 2.9k 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.
  • E Offline
    E Offline
    enmaniac
    wrote on last edited by enmaniac
    #1

    Hi all,

    I wonder if there is a way to install own handler for Q_ASSERT in runtime ? Something similar to qInstallMessageHandler ?

    Cheers!

    kshegunovK 1 Reply Last reply
    0
    • E enmaniac

      Hi all,

      I wonder if there is a way to install own handler for Q_ASSERT in runtime ? Something similar to qInstallMessageHandler ?

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      No, there's no such thing. Asserts are there for debug purposes, if you're tripping an assertion, then you have a bug that you need to fix.

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      0
      • E Offline
        E Offline
        enmaniac
        wrote on last edited by
        #3

        Yes indeed.

        Though, currently, I am running into such situation where I do have some tests which expects some failures under certain cases.
        In the code, however, there are some asserts which break the code flow. Due to that, testing is only possible in Release mode which usually is fine except the cases where there is something wrong and I want to debug it. Unfortunately, it is not easy as I need to comment out all asserts on the way and once bug is fixed, revert them back. A bit of a pain really :/

        Cheers!

        K 1 Reply Last reply
        0
        • E enmaniac

          Yes indeed.

          Though, currently, I am running into such situation where I do have some tests which expects some failures under certain cases.
          In the code, however, there are some asserts which break the code flow. Due to that, testing is only possible in Release mode which usually is fine except the cases where there is something wrong and I want to debug it. Unfortunately, it is not easy as I need to comment out all asserts on the way and once bug is fixed, revert them back. A bit of a pain really :/

          K Offline
          K Offline
          koahnig
          wrote on last edited by
          #4

          @enmaniac

          Are those Q_ASSERT in your own code?
          If the Q_ASSERT are in Qt, you need to fix the problems ASAP anyway, because you cannot rely on the outcome. Q_ASSERT is used when there is an unrecoverable situation.

          When you have the Q_ASSERT in your code and those are not essential, unrecoverable bugs, you might think over your strategy. Otherwise those bugs you have to fix anyway.

          Vote the answer(s) that helped you to solve your issue(s)

          1 Reply Last reply
          0
          • E Offline
            E Offline
            enmaniac
            wrote on last edited by
            #5

            No it is not in QT code it is in a code which uses QT.
            Q_ASSERTS. in this case, are used to indicate contract violations. For instance, when client passes argument containing a wrong value into the function. The function can deal with it in such sense that it will not explode out of the suddent (to make sure in production code no crashes occur) but still in debug mode it is convinient to slap developers ego and show him thats something is really out of place.

            Eh indeed I need to think about it a bit more.

            Thanks for the input and for answering my question!

            Cheers!

            kshegunovK 1 Reply Last reply
            0
            • E enmaniac

              No it is not in QT code it is in a code which uses QT.
              Q_ASSERTS. in this case, are used to indicate contract violations. For instance, when client passes argument containing a wrong value into the function. The function can deal with it in such sense that it will not explode out of the suddent (to make sure in production code no crashes occur) but still in debug mode it is convinient to slap developers ego and show him thats something is really out of place.

              Eh indeed I need to think about it a bit more.

              Thanks for the input and for answering my question!

              kshegunovK Offline
              kshegunovK Offline
              kshegunov
              Moderators
              wrote on last edited by kshegunov
              #6

              As said asserts are not intended to filter out user data, they are there to catch programming errors. If your user can pass you incorrect data, then it's the developer's job to sanitize it and if needed show error messages and handle the error. If the developer's not done his/hers job properly, then it should trip an assertion which is to show that the situation should be fixed. This is not a way to "slap developer's ego" but to catch their misses.

              Read and abide by the Qt Code of Conduct

              1 Reply Last reply
              2

              • Login

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