how should I load images in a different thread?

137 views Asked by At

how can i run below function in another thread in Qt?

void Dialog::on_loadPicture()
{

    ui->listWidget->setViewMode(QListWidget::IconMode);
    ui->listWidget->setIconSize(QSize(80,100 ));
    ui->listWidget->setResizeMode(QListWidget::Adjust);
    ui->progressBar->setMaximum(vec.size());
    ui->progressBar->setMinimum(progress.min());
    QDirIterator it(path , QDirIterator::Subdirectories);
    connect(&progress , SIGNAL(signalProgress(int)) , ui->progressBar , SLOT(setValue(int)));
    progress.emit50();


    while(it.hasNext())
    {
        item=new QListWidgetItem(QIcon(it.next()) , QString("1 (" +  (QString::number(9)) + ").jpg"  ));
        QVariant pathData(it.filePath());
        item->setData(Qt::UserRole , pathData);
        ui->listWidget->addItem(item);
        this->repaint();
        ui->listWidget->repaint();
        n++;
        emit progress.signalProgress(n);
    }
}

i used signal and slot like this:

  connect(&secthread , &thread2::loadPicture , this ,&Dialog::on_loadPicture );
 QFuture<void> future2=QtConcurrent::run(&this->secthread , &thread2::start);

but i guess (this) word make my main thread freeze.

0

There are 0 answers