How to log all application printouts in QML?
-
Hello, I'm trying to figure out if it's possible to display everything that is displayed in the QT-Creator output tab inside a QML text element as the application runs for logging and debug purposes...
-
Hello, I'm trying to figure out if it's possible to display everything that is displayed in the QT-Creator output tab inside a QML text element as the application runs for logging and debug purposes...
@Curtwagner1984 It would be quite easy as long as you have a C++ side to your QML app. All that stuff is done via stdout/stderr so you could capture that and push it to a QML widget.
-
qInstallMessageHandler
-
@Curtwagner1984 It would be quite easy as long as you have a C++ side to your QML app. All that stuff is done via stdout/stderr so you could capture that and push it to a QML widget.
I have a C++ side, but sadly I'm not sure how to redirect stdout/stderr to QML, is it an event ?
@Jacob.zhang said in How to log all application printouts in QML?:
qInstallMessageHandler
A little elaboration would go a long way.
-
I have a C++ side, but sadly I'm not sure how to redirect stdout/stderr to QML, is it an event ?
@Jacob.zhang said in How to log all application printouts in QML?:
qInstallMessageHandler
A little elaboration would go a long way.
@Curtwagner1984 There's many examples on how to capture stdout/stderr in both raw C, C++ and with Qt, so I'll let you just google that.
As for connecting the C++ with QML you can just send events or update your qml widget directly with C++. You can find it as a QObject and work directly on it's members.
Something like this:
auto passwordField = qmlObject_->findChild<QObject *>("pwField"); if (!passwordField) { so << "failed to find pwField" << endl; return false; } connect(passwordField, SIGNAL(accepted(QString)), operators_, SLOT(login(QString)));
In this code I have an
accepted(pin)
signal in my qml that talks to my C++ side for verification. That then calls aloginResult()
function in my qml object.I can't share all the code since I wrote it for a client and it's not mine to share, but you can find plenty of information on how to do that in the qmlbook online:
-
@Curtwagner1984 There's many examples on how to capture stdout/stderr in both raw C, C++ and with Qt, so I'll let you just google that.
As for connecting the C++ with QML you can just send events or update your qml widget directly with C++. You can find it as a QObject and work directly on it's members.
Something like this:
auto passwordField = qmlObject_->findChild<QObject *>("pwField"); if (!passwordField) { so << "failed to find pwField" << endl; return false; } connect(passwordField, SIGNAL(accepted(QString)), operators_, SLOT(login(QString)));
In this code I have an
accepted(pin)
signal in my qml that talks to my C++ side for verification. That then calls aloginResult()
function in my qml object.I can't share all the code since I wrote it for a client and it's not mine to share, but you can find plenty of information on how to do that in the qmlbook online:
Thank you, I'll try that and report back...