Search code examples
qtbrowserkill-processqprocess

QProcess: Destroyed while process (Web Browser) is still running


Is it possible to close a window or tab in an external browser after starting it using a Qprocess?

I tried the following (for example):

#include <QCoreApplication>
#include "QProcess"
#include "QThread"

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    QProcess process;
    process.start("C:/Program Files/Google/Chrome/Application/Chrome.exe", QStringList() << "google.com");
    QThread::msleep(1000);
    process.kill();
    process.waitForFinished();

    return a.exec();
}

But the process is not closed.

So, Is it not possible or there is a workaround? thanks.


Solution

  • Well this is not the best solution but I here it is:

    QProcess::execute("taskkill", QStringList() << "/IM" << "chrome.exe" << "/F");
    

    It only works on windows system and closes all browser windows but that is the only solution I have reached and will use for now.