Can you configure Qt Creator to kill the running application before building or running?

前端 未结 5 436
耶瑟儿~
耶瑟儿~ 2021-02-04 08:47

I\'m developing a QApplication and I find that I often forget to close my application before rebuilding and re-running it. This becomes a problem when I accidentally look at an

5条回答
  •  隐瞒了意图╮
    2021-02-04 09:25

    Yes.

    One way is to create a very simple script that kills your existing running process and starts a new one. If your program executable is FooBarProgram then go to the build directory that Qt has created and create this file FooBarProgramLauncher

    #!/bin/bash
    
    killall FooBarProgram
    ./FooBarProgram
    

    Now change the Qt project configuration to run your launcher instead running your program directly:

    1. Open the project in Qt Creator
    2. Select "Projects" from the pane on the left
    3. Select the "Build & Run" tab if not already selected
    4. Select the "Run" subtab
    5. Under the "Run" heading, click the "Add" button, select "Custom Executable"
    6. On the "Command" line, click the "Browse" button and select FooBarProgramLauncher

    Now whenever you tell Qt to run your program it will run FooBarProgramLauncher instead which in turn will kill any running instances of FooBarProgram and then run the newly compiled executable.

提交回复
热议问题