Restarting a Qt app programmatically

I had a requirement to restart some Qt apps remotely. This kind of thing can be a little tricky in a multi-platform environment but of course Qt makes it nice and easy – just four lines of code:

    QStringList args = QApplication::arguments();
    args.removeFirst();
    QProcess::startDetached(QApplication::applicationFilePath(), args);
    QCoreApplication::quit();

The removeFirst() is needed because the first string in the list is the app name – the result is just the arguments that were originally passed to the app.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s