How to close already open browser from application in Qt

Go To


I am using QDeskTopServices to open a URL in my application in Qt, but if the browser is already open in background, it does not come to the foreground and does nothing on calling on QDeskTopServices.

Is there any way to check and close the browser if it is already open in background?

2012-04-04 07:45
by abhishek
There is no such check. Bringing a running browser to the foreground might not be allowed by the windowing system (In Windows the foreground process needs to allow that). If it doesn't open the URL even in the background, that'd be a bug. Which platform are you on - Frank Osterfeld 2012-04-04 08:33
which platform you are coding for, for symbian, i think you needs special capability for doing this - Kunal 2012-04-04 09:11
@Kunal I am coding for symbain platform, I am trying this link also, but it is showing me error linkabhishek 2012-04-04 09:52
@FrankOsterfeld I am trying to close the browser if it already ope - abhishek 2012-04-04 10:08
I am not sure, how you can close browser, but you can bring forward existing browser by adding SwEvent" capability. TARGET.CAPABILITY += "SwEvent - Kunal 2012-04-04 12:17
Why?? If any application would close my browser without my consent, I would send letter bombs to the developer - Frank Osterfeld 2012-04-04 12:51
@FrankOsterfeld I have able to bring the browser to front but it is not showing my url. It is showing the old Url, I dont know wh - abhishek 2012-04-04 13:59


I found an answer for bringing browser to front but still work needed to pass the Url to browser.

#if defined(Q_WS_S60)
    TPtrC16 textPtr(reinterpret_cast<const TUint16*>(theUrl.utf16()));
    HBufC *param = HBufC::NewMaxLC(textPtr.Length());

    RApaLsSession apaLsSession;
    const TUid KBrowserUid = {0x10008D39};

    TApaTaskList taskList(CEikonEnv::Static()->WsSession());
    TApaTask task = taskList.FindApp(KBrowserUid);
    if (task.Exists()){
        // Switch to existing browser instance
        HBufC8* param8 = HBufC8::NewLC(param->Length());
        task.SendMessage(TUid::Uid(0), *param8); // UID not used
    else {
        if(!apaLsSession.Handle()) {
        TThreadId thread;
        User::LeaveIfError(apaLsSession.StartDocument(*param, KBrowserUid, thread));


If any suggestion then please add it to the answer.

Problem solved, just add "symbian:TARGET.CAPABILITY += SwEvent" in your file and make signed app. This will solve the problem :)

2012-04-05 15:28
by abhishek
@Kunal do you have any inputs on this answer? - abhishek 2012-04-09 15:13
@kunal Thanks for your hel - abhishek 2012-04-20 07:00



using the above line you can open browser. And also just add "symbian:TARGET.CAPABILITY += SwEvent" in your file and make signed app.

Refer this LINK

2012-05-13 16:39
by Shankar Agarwal