How to close an already open browser from an application in Qt

I use QDeskTopServices

to open a url in my application in Qt, but if the browser is already open in the background, it doesn't come to the front and does nothing when called QDeskTopServices

.

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

+3


source to share


2 answers


I found an answer for bringing the browser to the front, but still need to do the passing of the Url to the 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, please add it to the answer.

Problem solved, just add "symbian: TARGET.CAPABILITY + = SwEvent" to your project.pro file and create a signed application. This will fix the problem :)

+1


source


QDesktopServices::openUrl(QUrl("http://google.com"));

      

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



Refer to LINK

0


source







All Articles