Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. desktop app crashed when multiple event loops are used in code
Forum Update on Monday, May 27th 2025

desktop app crashed when multiple event loops are used in code

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
2 Posts 2 Posters 506 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rahush
    wrote on 5 Apr 2017, 15:16 last edited by
    #1

    I am trying to write some data to an url using get request from QNetworkAccessManager class. I am creating an event loop in it. There is another event loop running in the main thread which is the main event loop for the application. The application is getting crashed when it reaches eventLoop.exec(); line in the code below. Any idea why is it happening??

    bool Write(QNetworkRequest request) const
    {
    QEventLoop eventLoop;
    connect(networkAccessManager.get(), &QNetworkAccessManager::finished, &eventLoop, &QEventLoop::quit);
    int count = 0;
    while (count < retryCount)
    {
    QNetworkReply* reply = networkAccessManager->get(request);
    eventLoop.exec();
    if (reply != NULL && reply->error() == 0)
    return true;
    count++;
    }
    return false;
    }

    **networkAccessManager is the QNetworkAccessManager object.

    K 1 Reply Last reply 5 Apr 2017, 15:42
    0
    • R rahush
      5 Apr 2017, 15:16

      I am trying to write some data to an url using get request from QNetworkAccessManager class. I am creating an event loop in it. There is another event loop running in the main thread which is the main event loop for the application. The application is getting crashed when it reaches eventLoop.exec(); line in the code below. Any idea why is it happening??

      bool Write(QNetworkRequest request) const
      {
      QEventLoop eventLoop;
      connect(networkAccessManager.get(), &QNetworkAccessManager::finished, &eventLoop, &QEventLoop::quit);
      int count = 0;
      while (count < retryCount)
      {
      QNetworkReply* reply = networkAccessManager->get(request);
      eventLoop.exec();
      if (reply != NULL && reply->error() == 0)
      return true;
      count++;
      }
      return false;
      }

      **networkAccessManager is the QNetworkAccessManager object.

      K Offline
      K Offline
      koahnig
      wrote on 5 Apr 2017, 15:42 last edited by
      #2

      @rahush

      There is no need to have duplicated threads in this forum.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0

      1/2

      5 Apr 2017, 15:16

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved