简体   繁体   中英

Is QNetworkReply::finished() signal called sequentially or simultaneously?

It's a HTTP request sending method. When the goal website responses, httpFinished() will be called.

void HTTPClientBase:: HttpRequestGet()
{
    QNetworkRequest network_request;

    network_request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
    network_request.setUrl(URL);

    reply = network_manager.get(network_request);
    connect(reply, SIGNAL(finished()), this, SLOT(httpFinished()));
}

void HTTPClientBase::httpFinished()
{
    // process the reply;
}

I can call HttpRequestGet() in a loop.

static HTTPClientBase myClient;
for(...)
{
  myClient.setUrl(...);
  myClient.HttpRequestGet();
}

Since the the request and response are async, so the loop can be done within an instant time. After several hundreds milliseconds, httpFinished() will be called successively.

I want to know httpFinished() will be called sequentially or simultaneously. In other words, if I need to concern simultaneous-programming problems, for example, writing the response datas into a single file.

The following statements indicate that the httpFinished method will not be executed more than once at the same time:

  • Slots are invoked when no synchronous task is executed.
  • HTTPClientBase is a QObject that lives in a thread so the execution of any of its methods implies that you cannot execute another task.
  • The task you do is not concurrence only an asynchronism.
  • The asynchronism of Qt is valid from a design point of view but actually executes its tasks synchronously.
  • In one thread only one task can be executed at a time and httpFinished is executed in the thread where HTTPClientBase lives.

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