Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. #include <QApplication>
  2.  
  3. static QFile file(QStringLiteral("test.log"));
  4.  
  5. void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &message)
  6. {
  7. const QString msg = qFormatLogMessage(type, context, message);
  8.  
  9. QTextStream stream(&file);
  10.  
  11. stream.setCodec("UTF-8");
  12. stream.setGenerateByteOrderMark(true);
  13.  
  14. stream << msg << endl;
  15. }
  16.  
  17. int main(int argc, char *argv[])
  18. {
  19. if(!file.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text))
  20. return -1;
  21.  
  22. qInstallMessageHandler(messageHandler);
  23.  
  24. qDebug() << "test test";
  25.  
  26. QApplication a(argc, argv);
  27.  
  28. return a.exec();
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement