Qt 调用本地浏览器打开URL
作者:互联网
点击Qt某些控件,查找本地浏览器打开前端传递的URL。
方法一:直接写死本地浏览器地址
1 QString programAdress = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" 2 QString m_strWebUrl = "http://www.baidu.com"; 3 QStringList arguments; 4 arguments << "--chrome-frame" << m_strWebUrl; 5 QProcess *chromeProcess = new QProcess(); 6 chromeProcess ->start(programAdress ,arguments );
方法二:本地库
1 SHELLEXECUTEINFOA info; 2 memset(&info, 0, sizeof(info)); 3 std::string url = "http://www.baidu.com"; 4 std::string text = url; 5 6 info.cbSize = sizeof(SHELLEXECUTEINFOA); 7 info.hwnd = NULL; 8 info.lpVerb = "open"; 9 info.lpFile = "chrome.exe"; 10 info.lpParameters = text.c_str(); 11 info.nShow = SW_SHOWMAXIMIZED; 12 13 bool ret = ShellExecuteExA(&info);
SHELLEXECUTEINFOA、ShellExecuteExA 源自:C:\Program Files (x86)\Windows Kits\8.1\Include\um\shellapi.h
SW_SHOWMAXIMIZED 显示方式 源自: C:\Program Files (x86)\Windows Kits\8.1\Include\um\WinUser.h
方法三:注册表
1 #ifdef WIN32 2 QSettings a("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\Chrome.exe",QSettings::NativeFormat); 3 QSettings strPath = a.value("Default").toString(); 4 QString strUrl = QString("\"%1\" %2").arg(strPath).srg(strUrl); 5 WinExec(strUrl.toStdString().c_str(),SW_SHOWNORMAL); 6 #else 7 QDesktopServices::openUrl(QUrl(strUrl)); 8 #endif
标签:info,Files,QSettings,浏览器,Qt,URL,SHELLEXECUTEINFOA,strUrl,QString 来源: https://www.cnblogs.com/lyx5990/p/12066663.html