larpon / QtFirebase

An effort to bring Google's Firebase C++ API to Qt + QML
MIT License
283 stars 83 forks source link

Debugging console #154

Closed Trikos closed 3 years ago

Trikos commented 3 years ago

Hi Larpoon, at the end I was able to make your app working. It was my fault because we were using AWS instead of google console to send the notification, but everything was set perfectly. Now Im interested in the console in the app, did you develop it using qt or is something with android? Could you released the QML page of that console (without the hot stuff), just the layout? I really need one of them for my project. Thank you

larpon commented 3 years ago

Hi @Trikos I'm glad to hear you got it working :slightly_smiling_face: I think you're referring to this ?

Trikos commented 3 years ago

Yes but you do you get the data inside the console? Im trying to print the qDebug from the C++ code inside this console. How do I achieve this? I think that if I write something I will be overwritten everytime

larpon commented 3 years ago

It's done in the App QML singleton. If you want to include qDebug messages from C++ I guess you could just set a message handler in C++ that redirects messages to a similar QML singleton or something?

Trikos commented 3 years ago

I don't know how to implement this handler. Right now I'm appending text into a QString and emitting a signal every time it gets updated, but it is a very bad implementation xD

larpon commented 3 years ago

I can' t help with any specific setups. I have this code in one of my projects:

void messageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
    QByteArray localMsg = msg.toLocal8Bit();
    const char *file = context.file ? context.file : "";
    const char *function = context.function ? context.function : "";
    switch (type) {
    case QtDebugMsg:
        //fprintf(stderr, "Debug (%s:%u) %s: %s\n", file, context.line, function, localMsg.constData());
        break;
    case QtInfoMsg:
        fprintf(stderr, "Info (%s:%u) %s: %s\n", file, context.line, function, localMsg.constData() );
        break;
    case QtWarningMsg:
        //fprintf(stderr, "Warning (%s:%u) %s: %s\n", file, context.line, function, localMsg.constData());
        break;
    case QtCriticalMsg:
        fprintf(stderr, "Critical (%s:%u) %s: %s\n", file, context.line, function, localMsg.constData());
        break;
    case QtFatalMsg:
        fprintf(stderr, "Fatal (%s:%u) %s: %s\n", file, context.line, function, localMsg.constData());
        break;
    }

}

int main(int argc, char *argv[])
{
   qInstallMessageHandler(messageOutput);

   ... <rest of your main.cpp> ...
}

So instead of using fprintf as I do in this example - you'd send a QString off to your QML object instead.

Trikos commented 3 years ago

What do you mean by "send a QString off to your QML"? I would replace fprintf with MyClass.MyQString = context.line. Or you are referring to my main QML object that it is always a QQuickView? `QQuickView *view = new QQuickView;

MyClass clss;

view->rootContext()->setContextProperty("MyClass", &clss);
view->setSource(QUrl("qrc:/Init.qml"));
view->setResizeMode(QQuickView::SizeRootObjectToView);
view->show();

return app.exec();`

Thank you, appreciate your master explanation and help

larpon commented 3 years ago

Whatever works I guess.

You could probably send messages via a SingletonInstance also - there's many ways to do it I think.

If the way you're doing it currently, works - I guess there's no need to fix it :wink:

Trikos commented 3 years ago

Ok, perfect and thanks again

larpon commented 3 years ago

@Trikos I'm glad to help :slightly_smiling_face: