How to add rows automatically with sleep?
Solved
General and Desktop
-
Hi everyone, I want to make my tableview to show rows automatically. The target is everytime the table shows 10 rows, then sleep 1s, then add 10 rows and continue...
I used QThread::sleep(1) in my loop, but it would not show data until all data was loaded, but what I want is showing data while loading.
My part code for testing this function is:QVector<QVector<QVariant>> d; for (int t = 1; t <= 10; t ++) { d.clear(); for (int i = 0; i < 10; i++) { QVector<QVariant> row; row.clear(); for (int j = 0; j < 3; j++) row.append(i*j*t); d.append(row); } tablemodel->addData(d); //addData is used to add all new data to model QThread::sleep(1); }
Please help me. Thanks in advance! :)
-
You're blokcing the event loop.
Use a QTimer to add the rows later - whyever this should be needed at all. -
@Christian-Ehrlicher Thank you very much! It solved my problem perfectly :)