Вопрос

I try to make log when something is wrong, so I want to write the class info and function name like this:

void MainWindowTest::testMethod()
{
    qDebug()<<QString("ClassName is:%0,Function Name is:%1")
              .arg(this->metaObject()->className()).arg("how to get method name");
}

how to do this?

Это было полезно?

Решение

You can use Q_FUNC_INFO

sample code:

qDebug() << "Function Name: " << Q_FUNC_INFO;

Refer Qt Documentation

Другие советы

QT_STRINGIFY

MainWindowVM::MainWindowVM(QObject* parent) : QObject(parent)
{
    QDebug() << QT_STRINGIFY(MainWindowVM);
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top