使用 qt creator 在带有 https 的网站上获取一些值

Getting some values using qt creator on a website with https

本文关键字:网站 获取 https creator qt 使用      更新时间:2023-10-16

所以我目前正在用QTCreator 5.0构建一个小应用程序。我尝试构建一个允许我连接到网站的应用程序(使用 HTTPS 而不是 HTTP)。到目前为止,我认为我能够将一些东西放在一起,但我遇到了麻烦(当然我确信这与http和https有关,但我不完全确定如何解决它)。

我收到此错误:

QSslSocket: cannot call unresolved function SSLv23_client_method
QSslSocket: cannot call unresolved function SSL_CTX_new
QSslSocket: cannot call unresolved function SSL_library_init
QSslSocket: cannot call unresolved function ERR_get_error
QSslSocket: cannot call unresolved function ERR_get_error

这是我提出的一些代码:

QString str;
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    m_manager = new QNetworkAccessManager(this);
    connect(m_manager, SIGNAL(finished(QNetworkReply*)),
         this, SLOT(replyFinished(QNetworkReply*)));
}
MainWindow::~MainWindow()
{
    delete ui;
}
void MainWindow::fetch()
{
    m_manager->get(QNetworkRequest(QUrl("https://btc-e.com/api/2/btc_usd/ticker")));
}
void MainWindow::replyFinished(QNetworkReply* pReply)
{
    QByteArray data = pReply->readAll();
    QString str(data);
}
void MainWindow::on_pushButton_clicked()
{
    fetch();
    ui->textBrowser->setText(str);
}

我看了如何获取网页的内容,它可能相关,但我不完全确定这是否适用于https

谢谢!

添加这个作为答案:

  1. 你应该链接到openssl。

  2. 您需要将ui->textBrowser->setText移动到replyFinished插槽。