QtConcurrent errors



  • 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)



  • @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?



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.