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. A problem about assert in QT
QtWS25 Last Chance

A problem about assert in QT

Scheduled Pinned Locked Moved Unsolved General and Desktop
assertmingw
8 Posts 5 Posters 3.5k 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.
  • C Offline
    C Offline
    cq_qt
    wrote on 4 Jun 2021, 11:55 last edited by cq_qt 6 May 2021, 04:16
    #1

    I'm using Creator. Qt verson is 5.15.2. The compiler is MinGW 8.1.0 32bit。
    The Operating system is windows 10.
    I have an exe and an dll.
    The exe invokes the dll and they runs well. t
    When I insert “assert(0&&"abc")” in the exe code, it will show the following message window. That's corret. The message tells me where the assertion failed and the Expression I wrote.
    1.png

    When I insert "assert(0&&"abc")" in the dll code, it will show the following message
    2.png
    This message is different from the first. It's useless.
    Actually, I run this via debug.
    The problem is that the same statement("assert(0&&"abc")") behaves differently in exe code and in dll code. Assert statement doesn't work in the dll code.
    This annoys me.
    Thank you.

    Hello, I did some more tests.
    When using msvc compiler, everything is right.
    click the exe code button
    msvc1.png
    click the dll code button.
    msvc2.png

    When using minGW compiler.
    click the exe code button.It is right.
    migwin1.png
    click the dll code button. In this example on my computer, the application crashed, showing nothing. Its window simply vanished.
    I don't know why. Maybe there is a bug in migGW compiler.
    Whatever, there is nothing I can do.
    Unfortunately, for some seasons, I have to use migGW to compile my project.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 4 Jun 2021, 12:08 last edited by
      #2

      @cq_qt said in A problem about assert in QT:

      Can anybody tell me what happened?

      You did something wrong and therefore Qt/c++ throws an assertion.

      Use a debugger, insect the stack trace and see where it crashes

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      C 1 Reply Last reply 4 Jun 2021, 12:44
      0
      • C Christian Ehrlicher
        4 Jun 2021, 12:08

        @cq_qt said in A problem about assert in QT:

        Can anybody tell me what happened?

        You did something wrong and therefore Qt/c++ throws an assertion.

        Use a debugger, insect the stack trace and see where it crashes

        C Offline
        C Offline
        cq_qt
        wrote on 4 Jun 2021, 12:44 last edited by
        #3

        @Christian-Ehrlicher
        My dll code and exe code are corrent and they runs well. the exe invokes the dll.
        When I insert “assert(0&&"abc")” in the exe code, it will show the first message window. That's corret.
        This message tells me where the assertion failed and the Expression I wrote.

        When I insert "assert(0&&"abc")" in the dll code, it will show the second message window because of "assert(0&&"abc")". The problem is this message is different from the first and useless.
        Why this happened? How can i solve it.

        J J 2 Replies Last reply 4 Jun 2021, 13:42
        0
        • C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 4 Jun 2021, 13:06 last edited by
          #4

          I don't understand what your real problem is.. use a debugger!

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          0
          • C cq_qt
            4 Jun 2021, 12:44

            @Christian-Ehrlicher
            My dll code and exe code are corrent and they runs well. the exe invokes the dll.
            When I insert “assert(0&&"abc")” in the exe code, it will show the first message window. That's corret.
            This message tells me where the assertion failed and the Expression I wrote.

            When I insert "assert(0&&"abc")" in the dll code, it will show the second message window because of "assert(0&&"abc")". The problem is this message is different from the first and useless.
            Why this happened? How can i solve it.

            J Offline
            J Offline
            JonB
            wrote on 4 Jun 2021, 13:42 last edited by
            #5

            @cq_qt
            Maybe the message is different when the assert() is in a DLL, I don't know. It would presumably be a PC thing anyway, or maybe compiler, but there's probably not much you can do about it if it behaves as you have shown.

            As @Christian-Ehrlicher says, why can't you run this via Debug from Creator (I admit I don't know if there is an QML issue about doing this)? Then when it hits that SEGV it should stop in the debugger and give you a stack trace, hopefully showing the DLL source code point.

            1 Reply Last reply
            0
            • K Offline
              K Offline
              KH-219Design
              wrote on 4 Jun 2021, 17:50 last edited by
              #6

              Like the other commentators, I am also confused about why the "Signal Received - Qt Creator" popup window is being labeled entirely useless. If you click "OK" on that popup, doesn't the debugger stop at the line of the failed assertion? I would expect that it does. If not, then maybe instead of clicking "OK" you might try leaving that popup open and clicking the "pause/break" option in the debugger (unless this popup is modal and prevents you from doing that).

              Is the code in the DLL running in a (non-main, non-GUI) thread?

              In terms of why the outcome is different in a DLL, I can brainstorm several reasons.

              MinGW provides its own assert.h header and its own implementation of the assert feature. However, maybe when the DLL is compiled it "sees" some other copy of the assert.h (https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/assert-macro-assert-wassert)

              Also, the behavior of assertions is affected by things like #define NDEBUG being present in the source code.

              Ultimately the complete explanation is knowable and discoverable. But somebody would have to analyze the details of how you compile and link main.cpp, how you compile and link the DLL, what is on the loader path when you run it all in the debugger, and the full header-inclusion graph (to see if various headers that are "seen" during compilation are setting and/or unsetting preprocessor symbols in surprising ways).

              If you really want to know, then a great adventure awaits you :)

              www.219design.com
              Software | Electrical | Mechanical | Product Design

              C 1 Reply Last reply 5 Jun 2021, 01:38
              0
              • C cq_qt
                4 Jun 2021, 12:44

                @Christian-Ehrlicher
                My dll code and exe code are corrent and they runs well. the exe invokes the dll.
                When I insert “assert(0&&"abc")” in the exe code, it will show the first message window. That's corret.
                This message tells me where the assertion failed and the Expression I wrote.

                When I insert "assert(0&&"abc")" in the dll code, it will show the second message window because of "assert(0&&"abc")". The problem is this message is different from the first and useless.
                Why this happened? How can i solve it.

                J Offline
                J Offline
                JoeCFD
                wrote on 4 Jun 2021, 18:39 last edited by JoeCFD 6 Apr 2021, 18:44
                #7

                @cq_qt Your dll has release build and will not show assert message. Your app code has debug build which shows assert.
                if you want to see the message in both builds, use exception handling.

                1 Reply Last reply
                2
                • K KH-219Design
                  4 Jun 2021, 17:50

                  Like the other commentators, I am also confused about why the "Signal Received - Qt Creator" popup window is being labeled entirely useless. If you click "OK" on that popup, doesn't the debugger stop at the line of the failed assertion? I would expect that it does. If not, then maybe instead of clicking "OK" you might try leaving that popup open and clicking the "pause/break" option in the debugger (unless this popup is modal and prevents you from doing that).

                  Is the code in the DLL running in a (non-main, non-GUI) thread?

                  In terms of why the outcome is different in a DLL, I can brainstorm several reasons.

                  MinGW provides its own assert.h header and its own implementation of the assert feature. However, maybe when the DLL is compiled it "sees" some other copy of the assert.h (https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/assert-macro-assert-wassert)

                  Also, the behavior of assertions is affected by things like #define NDEBUG being present in the source code.

                  Ultimately the complete explanation is knowable and discoverable. But somebody would have to analyze the details of how you compile and link main.cpp, how you compile and link the DLL, what is on the loader path when you run it all in the debugger, and the full header-inclusion graph (to see if various headers that are "seen" during compilation are setting and/or unsetting preprocessor symbols in surprising ways).

                  If you really want to know, then a great adventure awaits you :)

                  C Offline
                  C Offline
                  cq_qt
                  wrote on 5 Jun 2021, 01:38 last edited by
                  #8

                  @KH-219Design
                  thank you, I‘ll try some tests.

                  1 Reply Last reply
                  1

                  1/8

                  4 Jun 2021, 11:55

                  • Login

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