View Full Version : how to self-destruct a program

21st January 2010, 10:54
Typically when I want to delete a file after the program stops running, I use atexit() and then remove(). Now I need to delete my Qt program itself (the .exe file) after it is done running. It's kind of like a self-destruction I need to achieve. Does Qt offer any solutions for that? I need to send my program to someone for testing. I then I need the program to delete itself because I don't want it to become public. What is the best way to achieve that with Qt? Thanks!

21st January 2010, 11:01

You can create another application "deleteApp" that deletes the file of your application. When your application is going to close you can start the other application using a QProcess.
In your application you can check if the "deleteApp" file exists to let it start or not.

But Qt don't will provide this thing for you

21st January 2010, 11:38
Thanks a lot!

I could use a little bit of help with starting another application with QProcess as I've never done this.
Is there a short example on how this is generally achieved?

21st January 2010, 11:42

You can use QProcess:startDeteched to start the second application.
The second application needs a delay to let the first application stop. There is a second way donig this that is using communication between the two applications.