• 11029阅读
  • 9回复

为什么不能使用QSslSocket [复制链接]

上一主题 下一主题
离线wan2004
 

只看楼主 倒序阅读 楼主  发表于: 2009-03-16
— 本帖被 XChinux 从 General Qt Programming 移动到本区(2011-01-02) —
源码如下
  1. #include <QtCore/QCoreApplication>
  2. #include <QtNetwork/QAbstractSocket>
  3. #include <QtNetwork/QSslSocket>
  4. #include <QtNetwork/QSslCertificate>
  5. #include <QtNetwork/QSslCipher>
  6. #include <QDebug>
  7. int main(int argc, char *argv[])
  8. {
  9.     QCoreApplication a(argc, argv);
  10.    QSslSocket socket;
  11. socket.connectToHostEncrypted("http.example.com", 443);
  12. if (!socket.waitForEncrypted()) {
  13.      qDebug() << socket.errorString();
  14.      return false;
  15. }
  16. socket.write("GET / HTTP/1.0\r\n\r\n");
  17. while (socket.waitForReadyRead())
  18.      qDebug() << socket.readAll().data();
  19.     return a.exec();
  20. }

编译提示
D:/Qt/workspace/TCP_Test/main.cpp:13: error: `QSslSocket' was not declared in this scope
D:/Qt/workspace/TCP_Test/main.cpp:13: error: expected `;' before "socket1"
D:/Qt/workspace/TCP_Test/main.cpp:15: error: `socket1' was not declared in this scope
D:/Qt/workspace/TCP_Test/main.cpp:13: warning: unused variable 'QSslSocket'

明明里面有QSslSocket的头文件

希望高手解答下
[ 此帖被wan2004在2009-03-16 14:41重新编辑 ]
离线XChinux

只看该作者 1楼 发表于: 2009-03-16
编译时添加openssl支持了吗?
二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
离线wan2004

只看该作者 2楼 发表于: 2009-03-16
QT += network
这个算不??
离线wan2004

只看该作者 3楼 发表于: 2009-03-16
还是在安装QT SDK的时候??
只看该作者 4楼 发表于: 2009-03-16
OpenSSL (version 0.9.7 or later)
Support for Secure Sockets Layer (SSL) communication is provided by the OpenSSL Toolkit, which must be obtained separately.
离线wan2004

只看该作者 5楼 发表于: 2009-03-16
谢谢
知道了
离线wan2004

只看该作者 6楼 发表于: 2009-03-16
都市无名者
我找到了一个openssl 0.9.8j 版本
并且编译好了
在怎么做才能用QSslSocket呢??
只看该作者 7楼 发表于: 2009-03-16
let the qt configure found ssl,
then configure qt with the parameter you need
    -no-openssl ........ Do not compile in OpenSSL support
   -openssl ........... Compile in run-time OpenSSL support
    -openssl-linked .... Compile in linked OpenSSL support

rebuild qnetwork and your code
离线wan2004

只看该作者 8楼 发表于: 2009-03-17
。。。。。。
最后得出一个结论了
我在linux上面执行的很好
用Qt SDK: Complete Development Environment for windows这个里面不能用QSslSocket
Qt libraries 4.5 for Windows 这个就可以用
看来官方打包的时候粗心了
离线chunpi
只看该作者 9楼 发表于: 2009-08-06
我在rebuild qnetwork 时出现以下错误,请指教
qhttpnetworkconnection.obj : error LNK2019: unresolved external symbol "protected: void __thiscall QHttpNetworkConnection::sslErrors(class QList<class QSslError> const &)" (?sslErrors@QHttpNetworkConnection@@IAEXABV?$QList@VQSslError@@@@@Z) referenced in function "public: void __thiscall QHttpNetworkConnectionPrivate::_q_sslErrors(class QList<class QSslError> const &)" (?_q_sslErrors@QHttpNetworkConnectionPrivate@@QAEXABV?$QList@VQSslError@@@@@Z)
qnetworkaccessmanager.obj : error LNK2019: unresolved external symbol "protected: void __thiscall QNetworkAccessManager::sslErrors(class QNetworkReply *,class QList<class QSslError> const &)" (?sslErrors@QNetworkAccessManager@@IAEXPAVQNetworkReply@@ABV?$QList@VQSslError@@@@@Z) referenced in function "public: void __thiscall QNetworkAccessManagerPrivate::_q_replySslErrors(class QList<class QSslError> const &)" (?_q_replySslErrors@QNetworkAccessManagerPrivate@@QAEXABV?$QList@VQSslError@@@@@Z)
qnetworkreplyimpl.obj : error LNK2019: unresolved external symbol "protected: void __thiscall QNetworkReply::sslErrors(class QList<class QSslError> const &)" (?sslErrors@QNetworkReply@@IAEXABV?$QList@VQSslError@@@@@Z) referenced in function "public: void __thiscall QNetworkReplyImplPrivate::sslErrors(class QList<class QSslError> const &)" (?sslErrors@QNetworkReplyImplPrivate@@QAEXABV?$QList@VQSslError@@@@@Z)
快速回复
限100 字节
 
上一个 下一个