Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
simon_hain
Posts: 15,874
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany
Accepted Solution

Code only in debug build?

We have a certain code part that we want only in a debug build, not in a release build. Is there a flag or variable that we can read with a preprocessing flag so that the code is only compiled in a debug build?
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
strobejb
Posts: 267
Registered: ‎10-15-2012
My Device: bb10 developer
My Carrier: Orange

Re: Code only in debug build?

there might be a better way, but I incorporate the following in the .PRO file:

 

CONFIG(release, debug|release) {
   DEFINES += RELEASE_BUILD
}

CONFIG(debug, debug|release) {
   DEFINES += DEBUG_BUILD
}

 Then in your c++ source files, you use the preprocessor macro as you'd expect:

 

#ifdef DEBUG_BUILD
/* this only gets compiled for a debug binary  */
#endif 

 

Please use plain text.
Developer
simon_hain
Posts: 15,874
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Code only in debug build?

Thanks, i used something similar before, but did not see the CONFIG section, i guess because it is in the pri file now.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
BlackBerry Development Advisor (Retired)
robbieDubya
Posts: 418
Registered: ‎07-18-2012
My Device: Q10
My Carrier: Bell Canada

Re: Code only in debug build?

No modifications needed for Qt standard defines:

 

QString ApplicationUI::text() {
#if defined(QT_DEBUG)
	return "Debug";
#elif defined(QT_NO_DEBUG)
    return "Release";
#else
    return "No idea";
#endif
}

 

--
Rob is no longer associated with BlackBerry.
Please use plain text.
Developer
simon_hain
Posts: 15,874
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Code only in debug build?

It seems we have an issue with the preprocessing.
If we clean the project and do a release it fails with an error message.
If we do a debug build and do a release afterwards we have the debug version of the preprocessed code.

Why would the "export release" build not re-build classes that were previously built with device-debug?
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
BlackBerry Development Advisor (Retired)
robbieDubya
Posts: 418
Registered: ‎07-18-2012
My Device: Q10
My Carrier: Bell Canada

Re: Code only in debug build?

Hi,

 

Was build before export checked?

 

Thanks.

--
Rob is no longer associated with BlackBerry.
Please use plain text.
Developer
simon_hain
Posts: 15,874
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Code only in debug build?

yes
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.