3

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?

abhishek
  • 857
  • 3
  • 13
  • 34
  • 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 Apr 04 '12 at 08:33
  • which platform you are coding for, for symbian, i think you needs special capability for doing this. – Kunal Apr 04 '12 at 09:11
  • @Kunal I am coding for symbain platform, I am trying this link also, but it is showing me error [link](http://www.developer.nokia.com/Community/Wiki/TSS000340_-_Launching_the_Web_browser_on_S60_3rd_Edition_to_open_a_specified_URL) – abhishek Apr 04 '12 at 09:52
  • @FrankOsterfeld I am trying to close the browser if it already open – abhishek Apr 04 '12 at 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 Apr 04 '12 at 12:17
  • Why?? If any application would close my browser without my consent, I would send letter bombs to the developer. – Frank Osterfeld Apr 04 '12 at 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 why – abhishek Apr 04 '12 at 13:59

2 Answers2

1

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());
    param->Des().Copy(_L("4 http://google.com"));

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

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

    CleanupStack::PopAndDestroy(param);
#else
    //QDesktopServices::openUrl(QUrl("http://google.com"));
#endif

If any suggestion then please add it to the answer.

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

alexisdm
  • 29,448
  • 6
  • 64
  • 99
abhishek
  • 857
  • 3
  • 13
  • 34
0
QDesktopServices::openUrl(QUrl("http://google.com"));

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

Refer this LINK

Shankar Agarwal
  • 34,573
  • 7
  • 66
  • 64