-2

I want to use console.log in my application to print output in console window, but the compiler reports this error

Description Resource    Path    Location    Type
'console' was not declared in this scope    CalcolatorQML.cpp   ‪/CalcolatorQML/src‬    line 27 C/C++ Problem

Now how can I solve it?

Thanks

Michael Donohue
  • 11,776
  • 5
  • 31
  • 44
JustMe
  • 732
  • 1
  • 11
  • 16

2 Answers2

1

If console.log() in QML and qDebug<< in CPP are not printing messages in console the use the following method in your main.cpp class

void myMessageOutput(QtMsgType type, const char* msg){
                fprintf(stdout, "%s\n", msg);                
                fflush(stdout);
} 

and the in main function use "qInstallMsgHandler(myMessageOutput);" like the following

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

}
pranavjayadev
  • 937
  • 7
  • 31
0

There is not a console windown on BB10. To log to the IDE console terminal you can use stdout/stderr (cout/cerr) but these should be removed prior to production. Output to stdout/stderr in production mode (with no debugger attached) ends up being stored on the device 'disk' taking up space and causing unneed wear on the flash devices.

For production error loggin you should use the slog2 facility either directly or by using the QDebug object.

Richard
  • 8,920
  • 2
  • 18
  • 24