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
Highlighted
Super Contributor
Posts: 253
Registered: ‎08-19-2010
My Device: BB10, Playbook, 9900, 9800, 9700, 9550, 9530, 9500, 8700.
My Carrier: TT
Accepted Solution

How to show text in console with printf??

Purpose: Debug the cascade cpp code.

 

Error:

'myMessageOutput' was not declared in this scope

 

Question: How to declare the void class in cascade ++??

                   How to printf??

 

 

Mini cod is at below

// Default empty project template
#include <bb/cascades/Application>

#include <QLocale>
#include <QTranslator>
#include "applicationui.hpp"

#include <Qt/qdeclarativedebug.h>
#include <QLocale>

 

#define QT_DECLARATIVE_DEBUG

using namespace bb::cascades;

//void myMessageOutput;

Q_DECL_EXPORT int main(int argc, char **argv)
{
// this is where the server is started etc
Application app(argc, argv);

qInstallMsgHandler(myMessageOutput);
#ifndef QT_NO_DEBUG
qInstallMsgHandler(myMessageOutput);
#endif

QTranslator translator;
QString locale_string = QLocale().name();
QString filename = QString( "SensorBB10_%1" ).arg( locale_string );
if (translator.load(filename, "app/native/qm")) {
    app.installTranslator( &translator );
}


     new ApplicationUI(&app);

    return Application::exec();
}

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

 

Thanks your attention,

 

-Fight with BB10
Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: How to show text in console with printf??

Hi,

 

Define myMessageOutput function before main() or, if it is implemented below main(), forward-declare it above main():

 

// somewhere above main():
void myMessageOutput(QtMsgType type, const char* msg);
Q_DECL_EXPORT int main(int argc, char **argv) { ...rest of the code... }

void myMessageOutput(QtMsgType type, const char* msg)
{
...implementation...
}

Also, you're calling qInstallMsgHandler(myMessageOutput) two times.

It shouldn't be used in release build, so you might want to leave only the one inside ifdef.

 

 


Andrey Fidrya, @zmeyc on twitter
Super Contributor
Posts: 253
Registered: ‎08-19-2010
My Device: BB10, Playbook, 9900, 9800, 9700, 9550, 9530, 9500, 8700.
My Carrier: TT

Re: How to show text in console with printf??

Thanks Zmey. Make another stupid mistake again. Sometimes, develop a new code, will forget the basic rule in c++.

 

Solution code is at below. Hopefully, help people to debug coding at Cascade C++.

 

// Default empty project template
#include <bb/cascades/Application>

#include <QLocale>
#include <QTranslator>
#include "applicationui.hpp"

#include <Qt/qdeclarativedebug.h>

#define QT_DECLARATIVE_DEBUG
using namespace bb::cascades;

#include <QString>

#include <QDebug>
#include <stdio.h>

 

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

 

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

// this is where the server is started etc
Application app(argc, argv);

qDebug() << QString::fromUtf8("i");

// localization support
QTranslator translator;
QString locale_string = QLocale().name();
QString filename = QString( "SensorBB10_%1" ).arg( locale_string );
if (translator.load(filename, "app/native/qm")) {
app.installTranslator( &translator );
}

 

new ApplicationUI(&app);

return Application::exec();
}

-Fight with BB10