Hey there guys,

i got a runtime error in this function here:

Qt Code:
  1. #include "logger.h"
  2.  
  3. #include <QApplication>
  4. #include <QDebug>
  5.  
  6. QString Logger::pathToLog = "";
  7.  
  8. const QString Logger::streamFiles[] = {
  9. "out.log", /// LS_STD
  10. "database.log", /// LS_DB
  11. "error.log" /// LS_ERR
  12. };
  13.  
  14. bool Logger::writeLog(LoggerStream stream, const QString &msg)
  15. {
  16. if (msg.isEmpty() || stream < 0 || stream >= LS_LAST)
  17. return false;
  18.  
  19. QString str;
  20. QFile * f;
  21. QDir * d;
  22.  
  23. str = DTime::dTimeToStr(QDateTime::currentDateTime());
  24. str.append(" : ");
  25. str.append(msg);
  26. str.append("\n\r");
  27.  
  28. if (pathToLog == "") {
  29. d = new QDir(qApp->applicationDirPath());
  30. if (!d->cd("data"))
  31. if (!d->mkdir("data") || !d->cd("data"))
  32. return false;
  33. pathToLog = d->path();
  34. }
  35.  
  36. switch (stream) {
  37. default : /// falls through
  38. case LS_STD:
  39. f = new QFile(pathToLog + QDir::separator() + streamFiles[LS_STD]);
  40. if (f->open(QIODevice::Append | QIODevice::Text)) {
  41. qWarning() << "filename = " + f->fileName();
  42. f->write(str.toAscii());
  43. f->close();
  44. return true;
  45. }
  46. break;
  47. case LS_DB :
  48. f = new QFile(pathToLog + QDir::separator() + streamFiles[LS_DB]);
  49. if (f->open(QIODevice::Append | QIODevice::Text)) {
  50. qWarning() << "filename = " + f->fileName();
  51. f->write(str.toAscii());
  52. f->close();
  53. return true;
  54. }
  55. break;
  56. case LS_ERR:
  57. f = new QFile(pathToLog + QDir::separator() + streamFiles[LS_ERR]);
  58. if (f->open(QIODevice::Append | QIODevice::Text)) {
  59. qWarning() << "filename = " + f->fileName();
  60. f->write(str.toAscii());
  61. f->close();
  62. return true;
  63. }
  64. break;
  65. }
  66.  
  67. return false;
  68. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. #ifndef LOGGER_H
  2. #define LOGGER_H
  3.  
  4. #include "dtime.h"
  5.  
  6. #include <QDir>
  7. #include <QFile>
  8.  
  9. class Logger
  10. {
  11. public:
  12. enum LoggerStream {
  13. LS_STD = 0,
  14. LS_DB,
  15. LS_ERR,
  16. LS_LAST
  17. };
  18.  
  19. static bool writeLog(LoggerStream stream, const QString &msg);
  20.  
  21. private:
  22. static QString pathToLog;
  23. static const QString streamFiles[LS_LAST];
  24. };
  25.  
  26. #endif // LOGGER_H
To copy to clipboard, switch view to plain text mode 

Every time i write to any output stream, all goes right. But when finishing the application, that means destruct my Database class, calling the logger from it's destructor, writes the output to the file "database.loŀ". Very strange...

Anyone sees the fault? I hope all the needed information are here. Thanks for a helpfull reply!

Regards