⚠️ Forum Maintenance: Feb 6th, 8am - 14pm (UTC+2)

Qt5 Ctrl-C not working when (sub-)QProcess is running

  • Hi,

    I have a console application that executes many subprocesses using QProcess. Under Linux, I cannot cancel the application using Ctrl-C any more, it simply has no effect. Any hints how I could fix that?

    I tried closing the write channel of QProcess, but no effect. I don't quite understand why executing a QProcess grabs the console input, shouldn't it run in the background?



  • Hi,
    How do you know that your application is to blame? Do you use seperated QProcess, or do you still control the programs in your main application? If so, the Ctr+C might not be executed by the 'slave' programs, so the standard closeEvent will probably ignore the request.
    In your main program add the closeEvent member function and check if the close is called. Then you are able to separate the program into pieces. In your close event signal all QProcesses that the program will be closed and accept the close program event.
    That might do the trick.

  • Hi Jeroen,

    thats what happens - the slave process gets canceled by Ctrl-C, but I want it to be my application that is canceled (including the slave process). I am not running an event loop, so catching the closeEvent probably won't help.

    To make it more clear: Compiling the application like this Ctrl-C works:

    @int main(int argc, char *argv[])

    but like this Ctrl-C is not working any more:

    @#include <QProcess>
    int main(int argc, char *argv[])
    QProcess p;

    I want to be able to cancel my applicaton with Ctrl-C. The application executed by QProcess should not receive it (and I don't know why it does, since AFAIK the QProcess streams should not be attached to the console).



    [edit: Added missing coding tags @ SGaist]

  • Hi,
    couple of issues: place code you past between the @ @ indication.
    That will give the code layout for better reading.

    Second of all, you generate a bit memory leak which IMHO should never be coded. You generate a QProcess on the stack every while loop? If so, you do not keep track of the QProcess after creation. The 'p' variable is just started. This is not so nice. What happens if your main program terminates with the memory that you allocated???? ..............answer: if your lucky, the OS will clean it for you, if your unlucky it will be cleared when the system reboots.

    No to your problem, what is the reason you do not use a QtCoreApplication? Is there a special reason for it?
    Then you are able to utilize the closeEvent and if you make all the QProcesses you generate children you could ignore the close for all of them. Now they probably listen to the standard in/out.
    So, they will get a closeEvent request from the OS.

Log in to reply