[Qt-interest] How to quit Qt app after browser opening?

程梁 chengliang.soft at gmail.com
Wed Jun 1 14:36:52 CEST 2011


Hi, there! I tried to develop an application to open the default web site
using Qt.

I use QDesktopServices::openUrl(theURL); to do this. But the problem is when
my default browser opens, the Qt application will not quit. What I want to
get is, after the browser opens, this Qt application quit automatically. But
I did not find how to do this. I tried this code:
    if(QDesktopServices::openURL())
        qApp->quit();
but it doesn't work. Here is my whole code, could you tell me how to solve
this problem?

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

{

    QApplication app(argc, argv);

    ConfigWindow w;

    QSettings settings(qApp->applicationDirPath().append(CONF_FILE_NAME),
QSettings::IniFormat);

    if(settings.contains(CONFIG_SERVER_URL)) {

        QString serverURL = settings.value(CONFIG_SERVER_URL).toString();

        if(QDesktopServices::openUrl(QUrl(serverURL, QUrl::TolerantMode))) {

            app.quit();

        }

    } else {

        w.show();

    }

    return app.exec();

}



-- 
Cheng Liang
from: chengliang.soft at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110601/1166d13a/attachment.html 


More information about the Qt-interest-old mailing list