LoginSignup
1
0

More than 1 year has passed since last update.

QNetworkRequest で https に対応させる

Posted at

はじめに

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

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
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0