You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

QNetworkAccessManager在libcrypto.so的lh_insert()中崩溃求助(Qt5.10爬虫)

Troubleshooting QNetworkAccessManager Crash in libcrypto's lh_insert() (Qt 5.10)

Hey there, let's break down the crash you're hitting in your Qt 5.10 crawler project—libcrypto's lh_insert() function crashing when using QNetworkAccessManager usually ties back to a few common issues, so let's work through them step by step:

1. Duplicate Signal-Slot Connections (Critical Fix!)

Looking at your code snippet, you’re calling connect(manager, SIGNAL(finished(QNetworkReply*)),&loop, SLOT(quit())) inside your while(true) loop. This creates a new signal-slot binding every iteration, meaning each request finish will trigger the quit() slot multiple times. Over time, this builds up invalid bindings, leading to memory corruption and crashes in low-level libraries like OpenSSL.

Fix: Move the connect call outside the loop so it only runs once:

std::string result = "";
QUrl url(inURL.c_str());
jar->setCookiesFromUrl(list, url);

// Connect ONCE before entering the loop
QEventLoop loop;
connect(manager, &QNetworkAccessManager::finished, &loop, &QEventLoop::quit);

while(true){
    QNetworkRequest request = QNetworkRequest(url);
    QNetworkReply *netReply = manager->get(request);
    loop.exec();

    if(netReply->error() == QNetworkReply::NoError){
        result = netReply->readAll().toStdString();
        // Process your result here
    } else {
        qDebug() << "Request failed:" << netReply->errorString();
    }

    // Critical: Clean up the reply to avoid memory leaks
    netReply->deleteLater();

    // Add an exit condition here to prevent infinite loop!
    // if (someStopCondition) break;
}

2. OpenSSL Version Compatibility

Qt 5.10 has specific dependencies on OpenSSL versions. If your system's libcrypto.so version doesn’t match the one Qt was compiled against, you can hit symbol conflicts or crashes in low-level SSL functions like lh_insert().

Check: Add this line to your code to verify Qt's SSL version:

qDebug() << "Qt SSL Library Version:" << QSslSocket::sslLibraryVersionString();

Compare this to your system's installed OpenSSL version (run openssl version in terminal). If they don’t align, either:

  • Install the matching OpenSSL version for your Qt 5.10 build
  • Recompile Qt with the OpenSSL version present on your system

3. Thread Safety Issues

QNetworkAccessManager and QNetworkCookieJar are not thread-safe. If your crawler uses these objects across multiple threads (e.g., starting requests from a worker thread while the jar is accessed from the main thread), race conditions can corrupt OpenSSL's internal structures, triggering crashes in lh_insert().

Fix:

  • Ensure all operations with manager and jar happen on the same thread
  • If using multi-threading, move the entire network logic to a dedicated worker thread, and use signal-slot communication to pass data instead of directly accessing network objects

4. CookieJar Mismanagement

If your QNetworkCookieJar (the jar variable) isn’t properly initialized, is deleted prematurely, or modified concurrently, it can pass invalid data to OpenSSL and cause crashes.

Check:

  • Verify jar is a valid, non-null pointer before calling setCookiesFromUrl()
  • If using a custom QNetworkCookieJar subclass, ensure all overridden methods (like cookiesForUrl() or setCookiesFromUrl()) are thread-safe
  • Avoid modifying the cookie jar while requests are in flight

Start with fixing the duplicate signal-slot connection first—it’s the most likely culprit here. If that doesn’t resolve the crash, move on to checking OpenSSL compatibility and thread safety.

内容的提问来源于stack exchange,提问作者mkuhlmann

火山引擎 最新活动