How disable QT_NO_EXCEPTIONS
-
wrote on 16 May 2017, 10:38 last edited by bronstein87
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 -
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@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. -
@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.wrote on 16 May 2017, 10:58 last edited by@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?
-
@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?
@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. -
@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.wrote on 16 May 2017, 11:11 last edited by bronstein87@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? -
@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?@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. -
@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.wrote on 16 May 2017, 11:21 last edited byhow 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.
-
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.
@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).
1/8