Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QtConcurrent errors
Qt 6.11 is out! See what's new in the release blog

QtConcurrent errors

Scheduled Pinned Locked Moved General and Desktop
3 Posts 1 Posters 1.1k Views 1 Watching
  • 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 Offline
    B Offline
    bagipro
    wrote on last edited by
    #1

    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
    0
    • B Offline
      B Offline
      bagipro
      wrote on last edited by
      #2

      @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
      0
      • B Offline
        B Offline
        bagipro
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0

        • Login

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