简体   繁体   中英

(Qt) QNetworkAccessManager slows down other application

It seems like after I create a QNetworkAccessManager object in Qt, it makes other applications (those who heavily uses network, such as multiplayer game) run slow.

For example, if I run Dota2 while running my app as a background, the game starts to lag even if my Qt app is very light (I checked through process explorer and it only consumes under 1% of CPU usage whole time). If I remove the QNetworkAccessManager part from the code, then game runs smoothly without any lagging.

Here is how I use QNetworkAccessManager;

QNetworkAccessManager *qnam = new QNetworkAccessManager(this);
response = qnam->get(QNetworkRequest(url));
connect(response , &QNetworkReply::finished, this, &Test::parse_response);

And in parse_response()

void parse_response() {
        // Network Error occured
        if (response->error() != QNetworkReply::NoError) {
            response->deleteLater();
            return;
        }

        response->deleteLater();
        qnam->deleteLater();
}

Funny thing is that when I check I/O usage of my app through process explorer, it shows weird activity on I/O usage

I / O的使用(标记为“其他”)。这些紫色的尖峰是我实际发出HTTP请求时发出的尖峰。其余的小峰值是未知的。顺便说一句,奇怪的I / O不断请求12.8KB

When I haven't used QNetworkAccessManager, that weird I/O Usage disappears. Hence I assume that my qnam has not been successfully deleted yet could not found any problem in my code.

If has anyone had similar experiences with this problem? Or is it just my configuration of usage of QNetworkAccessManager incorrect?

I found out that it was a bug within QNetworkAccessManager.

In Wireless environment, QNetworkAccessManager scans the wifi status every few seconds. Those little spikes were the evidence for that. Check the following bug report.

https://bugreports.qt.io/browse/QTBUG-40332

To solve this problem, either compile with

-D QT_NO_BEARERMANAGEMENT 

option or just remove bearer folder in a plugin.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM