Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    QtConcurrent errors

    General and Desktop
    1
    3
    833
    Loading More Posts
    • 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.
    • B
      bagipro last edited by

      I have the code
      @int countThreads = 3;
      for(int i=0;i<countThreads;i++)
      {
      QFuture<void> future = QtConcurrent::run(this,&MainWindow::thread);
      threads.push_back(future);
      }@

      @void MainWindow::thread()
      {
      while(lastLink < countLinks)
      {
      int i = lastLink;
      QString req = doRequest(links[i]);
      }
      }@

      @QString MainWindow::doRequest(QString url)
      {
      QString out;
      QTimer timer;
      QNetworkAccessManager* manager = new QNetworkAccessManager;
      QEventLoop loop;
      QObject::connect(&timer,SIGNAL(timeout()),&loop,SLOT(quit()));
      QObject::connect(manager,SIGNAL(finished(QNetworkReply*)),&loop,SLOT(quit()));
      QNetworkReply* reply = manager->get(QNetworkRequest(QUrl(url)));
      timer.start(TIMEOUT);
      loop.exec();
      if(!timer.isActive())
      {
      reply->abort();
      }
      else
      {
      if(reply->error() == QNetworkReply::NoError)
      {
      out = static_cast<QString>( reply->readAll() );
      }
      reply->close();
      }
      delete manager;
      return out;
      }@

      This code must do requests to links with 3 threads, but it do in 1. (In random moment 3 connection, but not 1)

      1 Reply Last reply Reply Quote 0
      • B
        bagipro last edited by

        @0 START
        0 WHILE
        0 WHILE
        0 WHILE
        0 WHILE
        0 WHILE
        0 WHILE
        0 WHILE
        0 WHILE
        0 WHILE
        0 WHILE
        0 WHILE
        0 WHILE
        0 WHILE
        0 WHILE
        0 WHILE
        1 START
        2 START @

        @ void MainWindow::thread(int num)
        {
        qDebug() << num << "START";
        while(lastLink < countLinks)
        {
        qDebug() << num << "WHILE";
        int i = lastLink;
        QString req = doRequest(links[i]);
        }
        }
        @

        WTF?

        1 Reply Last reply Reply Quote 0
        • B
          bagipro last edited by

          Fixed
          @QThreadPool::globalInstance()->setMaxThreadCount(100);@

          1 Reply Last reply Reply Quote 0
          • First post
            Last post