QListview flickers when model updates in another thread



  • I am updating my QStandardItemModel in a separate thread but QListView flickers while it updates. I am using QtConcurrent::run to do that, its dumb question but will it make any better if I do using QThread instead? IS there a way to remove the flicker?

    // somewhere on button click. I start the search in a separate thread which updates the model
    @void MainWindow::on_pushButtonConvert_clicked()
    {
    // ...
    QtConcurrent::run( this, &MainWindow::convertXmlFiles, sourceDir.absolutePath(), destDir.absolutePath() ) ;
    }@

    @int MainWindow::searchXmlFiles(QString rootDir)
    {
    clear();

    int count = 0;
    
    QString xmlFilePath;
    
    QDirIterator iter( rootDir, QStringList() << "*.xml", QDir::Files | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
    
    QDir dir( rootDir );
    
    while(iter.hasNext() )
    {
        iter.next();
    
        xmlFilePath = iter.filePath();
    
        QStandardItem * item = new QStandardItem( QIcon(":/icons/Progeny.ico") , dir.relativeFilePath( xmlFilePath) );
    
        appendRow( item );
    
        count++;
    }
    
    return count;
    

    }@


  • Lifetime Qt Champion

    Hi,

    You should not update your models directly from a different thread. Both view and model should live in the GUI thread. Some more information "here":http://stackoverflow.com/a/9489604


Log in to reply
 

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