zoukankan      html  css  js  c++  java
  • 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
    发上等愿,结中等缘,享下等福;择高处立,就平处坐,向宽处行。
  • 相关阅读:
    在Ubuntu上安装PHPStudy组件
    手把手教你在Ubuntu上分别安装Nginx、PHP和Mysql
    ErrorKiller:Failed to decode response: zlib_decode(): data error
    HTTP和FTP上传文件的区别
    关于HTTP,你知道哪些?
    史上最全的FTP网址
    深入解读TCP/IP
    nefu 462 fib组合
    MZL's xor
    The Highest Mark(01背包)
  • 原文地址:https://www.cnblogs.com/lyx5990/p/12066663.html
Copyright © 2011-2022 走看看