tableWidget怎么实现大量数据的删除又不卡界面
while (rowCount > 0)
{
int rowsToDelete = qMin(rowCount, 2000);
ui->tableWidget->setRowCount(rowCount - rowsToDelete);
QCoreApplication::processEvents(); // 处理事件,防止界面卡顿
rowCount -= rowsToDelete;
}
百万条数据的时候会卡住几下
// 创建一个局部的事件循环
QEventLoop loop;
connect(this,&MainWindow::quitLoop,&loop,&QEventLoop::quit);
QTimer::singleShot(0, [this](){
// 删除所有行
int rowCount = ui->tableWidget->rowCount();
while (rowCount > 0)
{
QThread::msleep(200);
int rowsToDelete = qMin(rowCount, 200);
ui->tableWidget->setRowCount(rowCount - rowsToDelete);
rowCount -= rowsToDelete;
if(rowCount == 0)
emit quitLoop();
}
});
loop.exec();
disconnect(this,&MainWindow::quitLoop,&loop,&QEventLoop::quit);
//这一种的话比上面还不行
第二种需要等几秒钟,变成这样才能拖动界面

好吧,第二种不行,后面就一直卡在那了