gpt4 book ai didi

qt - 如何从 Qt 中的应用程序关闭已打开的浏览器

转载 作者:行者123 更新时间:2023-12-02 04:11:33 30 4
gpt4 key购买 nike

我正在使用 QDeskTopServices 在 Qt 中的应用程序中打开 URL,但是如果浏览器已在后台打开,则它不会进入前台,并且在调用 时不会执行任何操作QDeskTopServices

如果浏览器已经在后台打开,有什么方法可以检查并关闭它吗?

最佳答案

我找到了将浏览器置于前端的答案,但仍需要将 URL 传递到浏览器。

#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

如果有任何建议,请将其添加到答案中。

问题已解决,只需在您的project.pro 文件中添加“symbian:TARGET.CAPABILITY += SwEvent”并制作签名应用程序即可。这将解决问题:)

关于qt - 如何从 Qt 中的应用程序关闭已打开的浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10006893/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com