Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
0
Help us understand the problem. What is going on with this article?
@c-toyama

QNetworkRequest で https に対応させる

はじめに

これも当たり前と思われ見つかられなかったので

QNetowrkRequest を OpenSSL のライブラリをリンクせずにプロジェクトをビルドし https でファイルをダウンロードするとエラーが発生する

qt.network.ssl: QSslSocket::connectToHostEncrypted: TLS initialization failed

OpenSSL 関連のライブラリをリンクする

確認に使用したプロジェクトは qtbase/examples/network/downloadmanager

downloadmanager.pro を開き 次のエントリーを追加

※Qtのインストール先が C:\Qt の場合

OPENSSL_DIR=C:/Qt/Tools/OpenSSL/Win_x64
LIBS += $${OPENSSL_DIR}/lib/libcrypto.lib
LIBS += $${OPENSSL_DIR}/lib/libssl.lib

これでリビルドすれば https も使用可能

配布する場合は C:/Qt/Tools/OpenSSL/Win_x64/bin/ 下の dll も忘れずに配布しましょう!

リンク前
> .\downloadmanager.exe https://www.google.com/

Downloading https://www.google.com/...
qt.network.ssl: QSslSocket::connectToHostEncrypted: TLS initialization failed
[###    ]      0.0 bytes/sec
Failed: TLS initialization failed
0/1 files downloaded successfully
リンク後
> .\downloadmanager.exe https://www.google.com/

Downloading https://www.google.com/...
[##################################################] 100% 157.3 kB/s
Succeeded.
1/1 files downloaded successfully
0
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
0
Help us understand the problem. What is going on with this article?