Is it possible to call slot "myMessageOutput_2" in MainWindow class from "myMessageOutput" in main.cpp.
I have to do it in this way because i have to catch what is printed in the "qtcreator_process_stub.exe" by a static function imported from an extenal library; so i can use what is catched in msg like i want in class MainWindow
#include "mainwindow.h"
#include <QApplication>
#include <QDebug>
#include <QMetaObject>
#include <QString>
void myMessageOutput
(QtMsgType type,
const QMessageLogContext
&context,
const QString &msg
) {
printf("1 PRINT - %s", msg.toUtf8().data());
//QUESTION - How to do:
QMetaObject::invokeMethod(MainWindow,
"myMessageOutput_2",
, /*What connection is needed*/, Q_ARG(QtMsgType, type),
QARG
(const QMessageLogContext
*,
&context
), Q_ARG
(const QString*,
&msg
));
//QUESTION
}
int main(int argc, char *argv[])
{
qInstallMessageHandler(myMessageOutput);
MainWindow w;
w.show();
return a.exec();
}
#include "mainwindow.h"
#include <QApplication>
#include <QDebug>
#include <QMetaObject>
#include <QString>
void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
printf("1 PRINT - %s", msg.toUtf8().data());
//QUESTION - How to do:
QMetaObject::invokeMethod(MainWindow, "myMessageOutput_2",
, /*What connection is needed*/, Q_ARG(QtMsgType, type),
QARG(const QMessageLogContext*, &context), Q_ARG(const QString*, &msg));
//QUESTION
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
qInstallMessageHandler(myMessageOutput);
MainWindow w;
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
and the classic Mainwindow files:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
{
Q_OBJECT
public:
MainWindow
(QWidget *parent
= nullptr
);
~MainWindow();
Q_INVOKABLE
void myMessageOutput_2
(QtMsgType type,
const QMessageLogContext
&context,
const QString &msg
);
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
Q_INVOKABLE void myMessageOutput_2(QtMsgType type, const QMessageLogContext &context, const QString &msg);
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
#include "mainwindow.h"
....
void MainWindow
::myMessageOutput_2(QtMsgType type,
const QMessageLogContext
&context,
const QString &msg
) {
// .. Do all i want ..
}
#include "mainwindow.h"
....
void MainWindow::myMessageOutput_2(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
// .. Do all i want ..
}
To copy to clipboard, switch view to plain text mode
Please write the right call that i try do in wrong way(see //QUESTION row on main.cpp)?
Bookmarks