According manual in order to log into file I need to open it in main
:
QScopedPointer<QFile> m_logFile;
void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg);
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
m_logFile.reset(new QFile("logFile.txt"));
// Открываем файл логирования
m_logFile.data()->open(QFile::Append | QFile::Text);
qInstallMessageHandler(messageHandler);
MainWindow w;
w.show();
return a.exec();
}
It works fine in case when I have created file. But how to create file if it not exist?