I have created a class for logging of errors into a text file, and the logging works, however I'm not seeing the destructor ever run.
I am testing this by having the destructor write to the file.
Can someone explain when the destructor is actually supposed to be called?

Thanks, this is my full code. If you can suggest a better way to code, please let me know, as I don't like doing things that work, but are not best coding practices.

Qt Code:
  1. #include "errorlogging.h"
  2.  
  3. ErrorLogging::ErrorLogging()
  4. {
  5. QString fileName = "c:/ProductionDB/SIMSErrors.daq";
  6. m_File = new QFile(fileName);
  7. m_File->open(QIODevice::Append | QIODevice::Text);
  8. }
  9.  
  10. void ErrorLogging::logError(QString timeStamp, QString classInstance, QString errorMsg)
  11. {
  12. QTextStream logStream(m_File);
  13. logStream << timeStamp << classInstance << errorMsg << "\n";
  14. }
  15.  
  16. ErrorLogging::~ErrorLogging()
  17. {
  18. QTextStream logStream(m_File);
  19. logStream << "File closing...";
  20. m_File->close();
  21. }
To copy to clipboard, switch view to plain text mode