I'm trying to reimplement a closeEvent handler but is not working as i want. I hope you can help me. I need start a python program as a last "task" of my main program. Here my first attempt.
Qt Code:
  1. void MainWindow::closeEvent(QCloseEvent *wd) {
  2. QString uploaderPath = "python " + QCoreApplication::applicationDirPath( ) + "/Uploader/setter.py";
  3.  
  4. QProcess *up = new QProcess( this );
  5. up->start( uploaderPath );
  6.  
  7. wd->accept();
  8. }
To copy to clipboard, switch view to plain text mode 
Error message when i close my main program:
QProcess: Destroyed while process ("python") is still running.
So, i tried to create a second thread where i could run this python program. I thought this program would run regardless of my main program. I close my main program, since the second(python) will run in another thread he will do what he should and will die too. But i was wrong. Here the code.
Second attempt.
Qt Code:
  1. #ifndef RESETTER_H
  2. #define RESETTER_H
  3.  
  4. #include <QtCore>
  5.  
  6. class Resetter : public QThread {
  7. public:
  8. Resetter( );
  9. void run( );
  10. };
  11.  
  12. #endif // RESETTER_H
To copy to clipboard, switch view to plain text mode 
Qt Code:
  1. #include "resetter.h"
  2.  
  3. Resetter::Resetter( ) { }
  4.  
  5. void Resetter::run( ) {
  6. QString uploaderPath = "python " + QCoreApplication::applicationDirPath( ) + "/Uploader/setter.py";
  7.  
  8. QProcess *up = new QProcess( this );
  9. up->start( uploaderPath );
  10. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. void MainWindow::closeEvent(QCloseEvent *wd) {
  2. Resetter rs;
  3.  
  4. rs.start( );
  5.  
  6. wd->accept();
  7. }
To copy to clipboard, switch view to plain text mode 

Error message when i close my main program:
QThread: Destroyed while thread is still running
Segmentation fault (core dumped)

Or create that object on the heap:
Qt Code:
  1. void MainWindow::closeEvent(QCloseEvent *wd) {
  2. Resetter *rs = new Resetter( );
  3.  
  4. rs->start( );
  5.  
  6. wd->accept();
  7. }
To copy to clipboard, switch view to plain text mode 
Error message when i close my main program:
QCoreApplication::applicationDirPath: Please instantiate the QApplication object first
QObject: Cannot create children for a parent that is in a different thread.
(Parent is QThread(0x112e700), parent's thread is QThread(0x1098e60), current thread is QThread(0x112e700)