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. How disable QT_NO_EXCEPTIONS

How disable QT_NO_EXCEPTIONS

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 2 Posters 3.4k 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.
  • B Offline
    B Offline
    bronstein87
    wrote on 16 May 2017, 10:38 last edited by bronstein87
    #1

    QVector is written in such a way that the allocated memory is checked using the macro Q_CHECK_PTR. In my program, with unsuccessful allocation Q_CHECK_PTR calls qFatal, which terminates the program. I do not like this behavior, I want to get an exception. In the source code, Q_CHECK_PTR looks like this:

    #ifdef QT_NO_EXCEPTIONS
    768 #  if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS)
    769 #    define Q_CHECK_PTR(p) qt_noop()
    770 #  else
    771 #    define Q_CHECK_PTR(p) do {if(!(p))qt_check_pointer(__FILE__,__LINE__);} while (0)
    772 #  endif
    773 #else
    774 #  define Q_CHECK_PTR(p) do { if (!(p)) qBadAlloc(); } while (0)
    775 #endif
    

    So, there is a way to call Q_CHECK_PTR exception version. But how ? I tried to compile with CONFIG += exceptions . But it doesnt't help.
    WIN 7 x32 , mingw-32

    J 1 Reply Last reply 16 May 2017, 10:56
    0
    • B bronstein87
      16 May 2017, 10:38

      QVector is written in such a way that the allocated memory is checked using the macro Q_CHECK_PTR. In my program, with unsuccessful allocation Q_CHECK_PTR calls qFatal, which terminates the program. I do not like this behavior, I want to get an exception. In the source code, Q_CHECK_PTR looks like this:

      #ifdef QT_NO_EXCEPTIONS
      768 #  if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS)
      769 #    define Q_CHECK_PTR(p) qt_noop()
      770 #  else
      771 #    define Q_CHECK_PTR(p) do {if(!(p))qt_check_pointer(__FILE__,__LINE__);} while (0)
      772 #  endif
      773 #else
      774 #  define Q_CHECK_PTR(p) do { if (!(p)) qBadAlloc(); } while (0)
      775 #endif
      

      So, there is a way to call Q_CHECK_PTR exception version. But how ? I tried to compile with CONFIG += exceptions . But it doesnt't help.
      WIN 7 x32 , mingw-32

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 16 May 2017, 10:56 last edited by
      #2

      @bronstein87 said in How disable QT_NO_EXCEPTIONS:

      I tried to compile with CONFIG += exceptions . But it doesnt't help.

      to compile what? You would need to compile Qt itself after setting QT_NO_EXCEPTIONS=0.
      This is Qt code and #ifdef is handled at compile time.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      B 1 Reply Last reply 16 May 2017, 10:58
      1
      • J jsulm
        16 May 2017, 10:56

        @bronstein87 said in How disable QT_NO_EXCEPTIONS:

        I tried to compile with CONFIG += exceptions . But it doesnt't help.

        to compile what? You would need to compile Qt itself after setting QT_NO_EXCEPTIONS=0.
        This is Qt code and #ifdef is handled at compile time.

        B Offline
        B Offline
        bronstein87
        wrote on 16 May 2017, 10:58 last edited by
        #3

        @jsulm said in How disable QT_NO_EXCEPTIONS:

        @bronstein87 said in How disable QT_NO_EXCEPTIONS:

        I tried to compile with CONFIG += exceptions . But it doesnt't help.

        to compile what? You would need to compile Qt itself after setting QT_NO_EXCEPTIONS=0.
        This is Qt code and #ifdef is handled at compile time.

        Thanks you for the answer. How can i do that? Where should i set QT_NO_EXCEPTIONS = 0? Can you give some link with example?

        J 1 Reply Last reply 16 May 2017, 11:02
        0
        • B bronstein87
          16 May 2017, 10:58

          @jsulm said in How disable QT_NO_EXCEPTIONS:

          @bronstein87 said in How disable QT_NO_EXCEPTIONS:

          I tried to compile with CONFIG += exceptions . But it doesnt't help.

          to compile what? You would need to compile Qt itself after setting QT_NO_EXCEPTIONS=0.
          This is Qt code and #ifdef is handled at compile time.

          Thanks you for the answer. How can i do that? Where should i set QT_NO_EXCEPTIONS = 0? Can you give some link with example?

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 16 May 2017, 11:02 last edited by jsulm
          #4

          @bronstein87 You will need to build Qt. Do you really want to do this? Why is the default behaviour of QVector an issue for you? Qt does not use C++ exceptions. What do you want to do if you cannot allocate memory any-more?
          I think you would need to pass "-UQT_NO_EXCEPTIONS" parameter to configure command.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          B 1 Reply Last reply 16 May 2017, 11:11
          0
          • J jsulm
            16 May 2017, 11:02

            @bronstein87 You will need to build Qt. Do you really want to do this? Why is the default behaviour of QVector an issue for you? Qt does not use C++ exceptions. What do you want to do if you cannot allocate memory any-more?
            I think you would need to pass "-UQT_NO_EXCEPTIONS" parameter to configure command.

            B Offline
            B Offline
            bronstein87
            wrote on 16 May 2017, 11:11 last edited by bronstein87
            #5

            @jsulm yes, i do. i need to avoid abort() which calls Q_CHECK_PTR version with defined QT_NO_EXCEPTIONS.

            What do you want to do if you cannot allocate memory any-more?
            

            I will clear part of used memory in catch() and continue to work.
            And if developers added version with exceptions, why it's bad to use it?

            J 1 Reply Last reply 16 May 2017, 11:17
            0
            • B bronstein87
              16 May 2017, 11:11

              @jsulm yes, i do. i need to avoid abort() which calls Q_CHECK_PTR version with defined QT_NO_EXCEPTIONS.

              What do you want to do if you cannot allocate memory any-more?
              

              I will clear part of used memory in catch() and continue to work.
              And if developers added version with exceptions, why it's bad to use it?

              J Offline
              J Offline
              jsulm
              Lifetime Qt Champion
              wrote on 16 May 2017, 11:17 last edited by jsulm
              #6

              @bronstein87 Well, then download Qt source code and build it. Don't forget to pass -UQT_NO_EXCEPTIONS as parameter to configure.
              "I will clear part of used memory in catch() and continue to work." - how will you decide which memory to free and how are you going to make sure your app does not crash because you freed some memory which is actually needed somewhere in your app?
              "And if developers added version with exceptions, why it's bad to use it?" - I did not say it's bad, I said that Qt by default does not use C++ exceptions. Even if you activate exceptions Qt will only use few of them.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              B 1 Reply Last reply 16 May 2017, 11:21
              0
              • J jsulm
                16 May 2017, 11:17

                @bronstein87 Well, then download Qt source code and build it. Don't forget to pass -UQT_NO_EXCEPTIONS as parameter to configure.
                "I will clear part of used memory in catch() and continue to work." - how will you decide which memory to free and how are you going to make sure your app does not crash because you freed some memory which is actually needed somewhere in your app?
                "And if developers added version with exceptions, why it's bad to use it?" - I did not say it's bad, I said that Qt by default does not use C++ exceptions. Even if you activate exceptions Qt will only use few of them.

                B Offline
                B Offline
                bronstein87
                wrote on 16 May 2017, 11:21 last edited by
                #7

                @jsulm

                how will you decide which memory to free and how are you going to make sure your app does not crash because you freed some memory which is actually needed somewhere in your app?
                

                My program plots a large number of graphs for a large amount of data. I'll just clean the charts already plot.

                J 1 Reply Last reply 16 May 2017, 11:26
                0
                • B bronstein87
                  16 May 2017, 11:21

                  @jsulm

                  how will you decide which memory to free and how are you going to make sure your app does not crash because you freed some memory which is actually needed somewhere in your app?
                  

                  My program plots a large number of graphs for a large amount of data. I'll just clean the charts already plot.

                  J Offline
                  J Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on 16 May 2017, 11:26 last edited by
                  #8

                  @bronstein87 OK. I hope it will work: if any memory is reserved during this clean up you will get out-of-memory exception again (or it will crash).

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0

                  1/8

                  16 May 2017, 10:38

                  • 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