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
Forum Update on Monday, May 27th 2025

QtConcurrent errors

Scheduled Pinned Locked Moved General and Desktop
3 Posts 1 Posters 983 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.
  • B Offline
    B Offline
    bagipro
    wrote on 29 Jun 2013, 15:11 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 29 Jun 2013, 15:51 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 30 Jun 2013, 08:53 last edited by
        #3

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

        1 Reply Last reply
        0

        2/3

        29 Jun 2013, 15:51

        • Login

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