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
Dredvard
Posts: 160
Registered: ‎01-27-2012
My Device: Playbook

Workaround: Debug messages to Console

Was reviewing the StumptheDev examples, and when I outputed my console.log and I notice it was actually piping it to the console - instead of having to do the slog2info.

 

I find this technique very nice as I hate having to figure out which run its from in the slog2info.  Anyway, I thought I'd post it here in case anyone else would like to use it:

 

Here is the main app:

using namespace bb::cascades;
void myMessageOutput(QtMsgType type, const char *msg)
 {
     //in this function, you can write the message to any stream!
     switch (type) {
     case QtDebugMsg:
         fprintf(stderr, "Debug: %s\n", msg);
         break;
     case QtWarningMsg:
         fprintf(stderr, "Warning: %s\n", msg);
         break;
     case QtCriticalMsg:
         fprintf(stderr, "Critical: %s\n", msg);
         break;
     case QtFatalMsg:
         fprintf(stderr, "Fatal: %s\n", msg);
         abort();
     }
 }

int main(int argc, char **argv)
{
	qInstallMsgHandler(myMessageOutput);
...

 

---
If you find my post helpful please "like" it and "accept as a solution"
Developer
testinz
Posts: 183
Registered: ‎09-03-2012
My Device: Blackberry 10

Re: Workaround: Debug messages to Console

So to trigger it, do we run: myMessageOutput(QtDebugMsg, "test"); ?

Thanks!



Developer
Dredvard
Posts: 160
Registered: ‎01-27-2012
My Device: Playbook

Re: Workaround: Debug messages to Console

Yeah... just place that in your main app and it will be your message handler which will put the errors in your console as Debug.  It will also label warnings as such as well.

---
If you find my post helpful please "like" it and "accept as a solution"
Developer
Dredvard
Posts: 160
Registered: ‎01-27-2012
My Device: Playbook

Re: Workaround: Debug messages to Console

I just reread your post and I think i answered it wrong.  To trigger this, you just need to do console.log or qDebug().   That will now automatically stream to the console.  Just copy those lines into main.cpp replacing :

 

int main(int argc, char **argv)
{

 

and all your errors, alerts,  and debug messages will now pop in the console.  You don't have to worry about views switching away from your terminal when trying to debug.

 

---
If you find my post helpful please "like" it and "accept as a solution"
Contributor
base8
Posts: 26
Registered: ‎06-27-2012
My Device: Playbook

Re: Workaround: Debug messages to Console

Yeah, all the automatic switching away from other tabs to the Console and the switching of consoles within that tab is enough to drive anybody crazy.
Developer
testinz
Posts: 183
Registered: ‎09-03-2012
My Device: Blackberry 10

Re: Workaround: Debug messages to Console

Work very well. I was thinking doing the other way won't help much :smileyhappy:

Thank you!
Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Workaround: Debug messages to Console

we implemented that yesterday, works like a charm!
----------------------------------------------------------
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
Contributor
base8
Posts: 26
Registered: ‎06-27-2012
My Device: Playbook

Re: Workaround: Debug messages to Console

It should be noted that a BlackBerry Development Advisor has noted in another thread that this situation is temporary and that the IDE will soon catch up with the slogger2 changes.

Developer
kanaksony
Posts: 571
Registered: ‎04-11-2009
My Device: BB 10 Dev Alpha

Re: Workaround: Debug messages to Console

Hi,

 

I also want to implement this.

 

int main(int argc, char **argv)
{
	qInstallMsgHandler(QtDebugMsg);
	//-- this is where the server is started etc
	Application app(argc, argv);
}
void myMessageOutput(QtMsgType type, const char *msg)
{
	//in this function, you can write the message to any stream!
	switch (type) {
	case QtDebugMsg:
		fprintf(stderr, "Debug: %s\n", msg);
		break;
	case QtWarningMsg:
		fprintf(stderr, "Warning: %s\n", msg);
		break;
	case QtCriticalMsg:
		fprintf(stderr, "Critical: %s\n", msg);
		break;
	case QtFatalMsg:
		fprintf(stderr, "Fatal: %s\n", msg);
		abort();
		break;
	}
}

 But at compilet time, its giving error - 

 

../src/main.cpp:13:31: error: cannot convert 'QtMsgType' to 'QtMsgHandler {aka void (*)(QtMsgType, const char*)}' for argument '1' to 'void (* qInstallMsgHandler(QtMsgHandler))(QtMsgType, const char*)'

 

How to do this?

 

Regards,
Kanak Sony
------------------------------------------------------------------------------------------
http://dodevelopnshare.wordpress.com/ | http://www.linkedin.com/profile/view?id=188131481&trk=tab_pro
Contributor
xtravanta
Posts: 46
Registered: ‎03-25-2011
My Device: Blackberry Z10

Re: Workaround: Debug messages to Console

i think you should change the
qInstallMsgHandler(QtDebugMsg);
to
qInstallMsgHandler(myMessageOutput);