Does Qt offer a (guaranteed) debug definition? - debugging

Does anyone know an officially supported way to include debug-build only code in Qt? For example:
#ifdef QT_DEBUG
// do something
#endif
Basically like Q_ASSERT but for more complex tests.
I can't seem to find any documentation which says that the Qt framework guarantees to define a debug macro. If there isn't, what would be a sensible unofficial way to implement this feature project wide?

Qt defines QT_NO_DEBUG for release builds. Otherwise QT_DEBUG is defined.
Of course you are free to specify any DEFINES in your .pro files and scope them for either debug or release.

An alternative is to write in your project file something like:
debug {
DEFINES += MYPREFIX_DEBUG
}
release {
DEFINES += MYPREFIX_RELEASE
}
Then you will not depend on the Qt internal definition.

For check debug mode:
#ifdef QT_DEBUG
//Some codes
#endif
For check release mode:
#ifndef QT_DEBUG //<== Please note... if not defined
//Some codes
#endif

Related

Preprocessor ifdef does not hide the code blocks in an Objective C framework

I am working on an Objective C framework and we want to hide some debug related methods in our release version. I thought using #ifdef DEBUG can easily server for that purpose, so put the debug related method in a #ifdef block:
#ifdef DEBUG
+(void)unregisterDevice OBJC_VISIBLE;
#endif
The above code block shows up exactly, in the aggregated framework when I build it with either of our Debug, or Release targets! I thought, the compiler would remove #ifdef and #endif when DEBUG is defined and will hide the whole block when DEBUG is not defined. Would you please help me resolve this issue?

What is macro SINIX stand for?

I am analyzing the code of a project.
There is some code gets compiled when SINIX is defined.
#ifdef SINIX
do something()
#else
do dosomethingelse()
#endif
Can anyone tell me if SINIX is OS specific define statement or it is a project specific.
Seems to be a project specific definition. My guess would be support for https://en.wikipedia.org/wiki/SINIX .
Grepping through the GCC sources, SINIX support was removed from GCC in 2003. Based on some ChangeLog entries, it seems GCC, back when it did support SINIX, set the predefined macros "SNI" and "sinix", but not "SINIX".

Visual Studios (Multiple Projects) Linking Error

I am working with Qt and Cryengine in visual studios. I am very new to large projects such as this one, but I am nearly to the point of actually adding something to this engine. My code compiles piece by piece, but when I try to compile my "Indie Game" project I get linking errors that after researching I still have no idea how to solve. I know the errors relate to my code InventoryGUI, because when I remove that file the project compiles fine with no linking errors.
This is my InventoryGUI code and the error that is displayed when trying to build Indie Game
http://imgur.com/hzmGdvH
This is the header file that it includes.
http://imgur.com/o22GHXg
I appreciate any help you guys can give on this. Of course, if you need to see different parts of my code, let me know and I will post it as well.
Thanks
Edit: Forgot to add that the function "createInventory()" calls the function InventoryGUI from a different project. I believe going between projects is very likely the cause of the errors.
if InventoryGUI class is defined in a shared library ("dll") and used in an executable, then you have to export its symbols (on Windows build that is).
so try something like :
#ifdef WIN32
# ifdef MY_LIB_EXPORTS
# define MY_LIB_DLL __declspec(dllexport)
# else
# define MY_LIB_DLL __declspec(dllimport)
# endif
#else
# define MY_LIB_DLL
#endif
class MY_LIB_DLL InventoryGUI
{
...
};
Then, the library defining InventoryGUI should have defined MY_LIB_EXPORTS.
For example if you use pro files system, it would look like
DEFINES += MY_LIB_EXPORTS
Other projects should not.
Check if there is a similar mechanism for the other classes of the library.

xcode -- conditional compilation based on build configuration

I'd like to compile differently based on which build configuration I'm using. Something like
#ifdef DEBUG
// debug code goes here
#endif
I know I can do this by defining preprocessor macros for each build configuration. But I'm wondering if there's already something built-in I can ues. Is there?
This is what I've always used and it's very clean. It also comes up when you search your code, which is nice, since settings, etc...may not.

How do I check the active solution configuration Visual Studio built with at runtime?

I would like to enable/disable some code based on a custom solution configuration I added in Visual Studio. How do I check this value at runtime?
You can use precompiler directives within Visual Studio. The #if directive will allow you to determine if you are going to include code or not based on your custom solution configuration.
add a const value assign to a value that designate the configuration you are in.
like
#ifdef _ENABLE_CODE1_
const codeconfig = 1;
#else
const codeconfig = 2;
#endif
and add _ENABLE_CODE1_ in your configuration preprocessor.
In each project's properties under the build section you can set different custom constants for each solution configuration. This is where you define custom pre-compiler directives.
I'm not sure if you can figure out the exact name of the build configuration. Howerver, if you use Debug.Assert(...), that code will only be run when you compile in debug mode. Not sure it that helps you at all.

Resources