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. QListview flickers when model updates in another thread
Qt 6.11 is out! See what's new in the release blog

QListview flickers when model updates in another thread

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.7k 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.
  • X Offline
    X Offline
    xalam
    wrote on last edited by
    #1

    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;
    

    }@

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      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