• Qt 调用本地浏览器打开URL


    点击Qt某些控件,查找本地浏览器打开前端传递的URL。

    方法一:直接写死本地浏览器地址

    1 QString programAdress = "C:Program Files (x86)GoogleChromeApplicationchrome.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 Kits8.1Includeumshellapi.h
    SW_SHOWMAXIMIZED  显示方式  源自: C:Program Files (x86)Windows Kits8.1IncludeumWinUser.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
    发上等愿,结中等缘,享下等福;择高处立,就平处坐,向宽处行。
  • 相关阅读:
    最长回文 hdu3068(神代码)
    1297. Palindrome ural1297(后缀数组)
    705. New Distinct Substrings spoj(后缀数组求所有不同子串)
    Milk Patterns poj3261(后缀数组)
    Musical Theme poj1743(后缀数组)
    Conscription poj3723(最大生成树)
    Drying poj3104(二分)
    Finding LCM (最小公倍数)
    002 全局配置信息
    001 开始
  • 原文地址:https://www.cnblogs.com/lyx5990/p/12066663.html
Copyright © 2020-2023  润新知