/* 方法一*/
QDesktopServices::openUrl(QUrl(QString("www.baidu.com")));
QUrl url(QString("www.baidu.com"));
bool is_open = QDesktopServices::openUrl(url);
/*方法二*/
QWebView *view;
view->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks); //设置打开连接的方式,默认是所有二级链接都不打开
connect(view, SIGNAL(linkClicked(QUrl)),this,SLOT(openUrlSlot(QUrl)));
view->load(QUrl("http://www.baidu.com/"));
view->show();
2.需要包含的头文件有: #include <QDesktopServices>#include <QUrl>#include <QWebView>
3.在.pro文件中需要添加:
QT += webkit 这句话
4.以上方法的实现需要在电脑中安装OpenSSL库
具体的安装步骤转载于:http://codeblog.vurdalakov.net/2009/11/solution-qsslsocket-cannot-call.html,http://blog.csdn.net/sgnh123456/article/details/8020683
这里面看到了解决办法,经过测试解决问题了!
步骤如下:
You need to install OpenSSL Win32 or Win64 binaries.
你需要安装OpenSSL库;
1、Open Win32 OpenSSL Installation Project page.
首先打开OpenSSL Installation Project网页;
2、Download the latest "light" Win32 or Win64 installation package, for example "Win32 OpenSSL v0.9.8l Light".
下载安装包,我下载的是:Win64 OpenSSL v1.0.2d Lightt安装包,随着时间的推进,这个版本会不断更新的!!
3、Install it to any location. Ignore "Microsoft Visual C++ 2008 Redistributables" warning (click OK) and select copying OpenSSL DLLs to "The OpenSSL binaries (\bin) directory".
安装(exe文件)到本地,我是安装到C盘下,并且在安装过程中选择将库安装到OpenSSL的安装目录(/bin)下面。
4、Copy libeay32.dll and ssleay32.dll from the \bin folder to the same place where your QtNetwork4.dll or QtNetworkd4.dll is located.
将libeay32.dll 和 ssleay32.dll 文件拷贝到QtSDK中的存放有QtNetwork4.dll和QtNetworkd4.dll的文件目录下。我的是
D:\Qt\Qt5.3.2\Tools\QtCreator\bin,这个主要是看自己选择的编译器也有可能是C:\QtSDK\Desktop\Qt\4.8.0\msvc2010\bin等等!