Hi, I try to write a blob to a file and then execute it. My code:
source:
Qt Code:
  1. ProgramLauncher::ProgramLauncher ( QObject *parent )
  2. : QObject ( parent )
  3. {
  4. loader = new BinaryLoader ( );
  5. connect ( loader, SIGNAL ( dataLoaded ( int, QByteArray ) ), this, SLOT ( loaded ( int, QByteArray ) ) );
  6. }
  7.  
  8. void ProgramLauncher::launch ( int id )
  9. {
  10. qDebug() << id;
  11. loader->getData ( "bin_programs", id );
  12. }
  13.  
  14. void ProgramLauncher::loaded ( int handle, QByteArray data )
  15. {
  16. Q_UNUSED ( handle );
  17. // QString path = QDir::tempPath() + "XXXXXX";
  18. QTemporaryFile *tmpFile = new QTemporaryFile ( QString ( "XXXXXX" ) );
  19. if ( !tmpFile->open ( ) )
  20. {
  21. return;
  22. }
  23. qDebug() << "tmpFile: " << tmpFile->fileName() << " opened";
  24. qint64 size = tmpFile->write ( data );
  25. if ( size != -1 )
  26. {
  27. qDebug() << "wrote " << size << " into the file";
  28. execute ( tmpFile );
  29. }
  30. }
  31.  
  32. void ProgramLauncher::execute ( QTemporaryFile *file )
  33. {
  34. QString path = QDir::tempPath() + "/" + file->fileName();
  35. qDebug() << "Launching filename " << path;
  36. qDebug() << QProcess::startDetached ( path );
  37. }
  38. ProgramLauncher::~ProgramLauncher()
  39. {
  40. }
To copy to clipboard, switch view to plain text mode 
header:
Qt Code:
  1. class ProgramLauncher : public QObject
  2. {
  3. Q_OBJECT
  4. public:
  5. ProgramLauncher ( QObject *parent = 0 );
  6. ~ProgramLauncher();
  7. public slots:
  8. void launch ( int id );
  9. void loaded ( int handle, QByteArray data );
  10. private:
  11. void execute ( QTemporaryFile *file );
  12. BinaryLoader *loader;
  13. };
To copy to clipboard, switch view to plain text mode 
My problem is that it doesn't create the file where it should. According to the doc, it should be in QDir::tempPath(), but instead it is where the program was started. So, starting the binary fails cause my functions look into /tmp:
Qt Code:
  1. 5
  2. tmpFile: "XN1408" opened
  3. wrote 24791336 into the file
  4. Launching filename "/tmp/XN1408"
  5. false
To copy to clipboard, switch view to plain text mode 
Why that?

The program is developed on linux, target platform will be windows where it should run from CD (so no write access).

And: I thought the file will be removed upon destruction of the object? it stays where it is, including content

C167