0

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?

vico
  • 17,051
  • 45
  • 159
  • 315
  • 1
    You need to ensure you use the `WriteOnly` or `ReadWrite` flags, as per: Possible duplicate of [How to create a new File with full path in Qt?](https://stackoverflow.com/questions/3024382/how-to-create-a-new-file-with-full-path-in-qt) – hnefatl Apr 03 '18 at 15:12

0 Answers0