10-07-2012 09:07 PM
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);
...
10-07-2012 10:36 PM
10-07-2012 11:15 PM
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.
10-09-2012 01:01 AM
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.
10-09-2012 02:36 PM
10-09-2012 09:54 PM
10-10-2012 03:31 AM
10-10-2012 09:29 AM
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.
10-12-2012 02:04 AM
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?
10-12-2012 04:03 AM