Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Sending Ctrl+C event to a process launched using QProcess on Windows
QtWS25 Last Chance

Sending Ctrl+C event to a process launched using QProcess on Windows

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 4.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bharath144
    wrote on last edited by
    #1

    Hello all,

    I have a dialog which acts as a configurator for a console application. The dialog's job is to offer the user a set of widgets (which mirror the options supported by the console application) and when user clicks on the "Start" button, the dialog creates and starts a QProcess with the console application's name and parameters based on the state of the widgets in the GUI. I am able to start the process successfully and everything works fine. However, when I want to kill the process, the console application needs to shutdown gracefully, meaning it has to close files, flush data, close devices etc., and then terminate.

    I used QProcess::close(), this immediately kills the application and the app is unable to shutdown gracefully.

    I have used the Win32 API GenerateConsoleCtrlEvent(CTRL_C_EVENT, Q_PID::dwProcessId) to send an even to the same. I see that the above API returns a non-zero value (indicating a success, it would return 0 upon failure), but my process continues to run.

    Can anyone help me with how I can signal the QProcess to shutdown gracefully? Or is there any other way to do this?

    Regards,
    Bharath

    Cheers!
    ಮೈ ಗೋ ಭರತ ನಾರಾಯಣ
    Bharath Narayan M G

    1 Reply Last reply
    0
    • F Offline
      F Offline
      francomartins
      wrote on last edited by
      #2

      if you are using Windows , u can use
      @
      QProcess p;
      p.execute("TASKKILL /PID ProcessID");
      @

      ProcessID = ID of u app ;

      1 Reply Last reply
      0
      • B Offline
        B Offline
        bharath144
        wrote on last edited by
        #3

        Thanks for the response, I will try that out.

        Cheers!
        ಮೈ ಗೋ ಭರತ ನಾರಾಯಣ
        Bharath Narayan M G

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved