Unsolved Fill QTableWidget
-
Hello everyone, I hope you are well.
I have been working with QT for about 1 year, now I have a new challenge where I have to display information.
I am using a QTableView for this, what happens is that when the table is filled, the software freezes and after it finishes filling it unfreezes. Can someone please indicate what is happening, thank you. -
@marango27 said in Fill QTableWidget:
Can someone please indicate what is happening, thank you.
Well, I guess you block the event loop with your long lasting operation. You need to provide more information if you want to get meaningful help.
- How many entries do you insert into the table?
- Are you doing any heavy calculations when filling the table?
- Can you show your code?
-
@jsulm thanks for you attention.
the entries are more or less than 2000 or 5000 rows. So right at the moment it starts inserting into the table it locks the entire interface and tries to crash the softwareLet's pretend that the arrangement I am going through has 2000 to 5000 entries, but even if they are less, it blocks and tries to fail. I've thought of using a helper class with a thread and pausing milliseconds for each input
model_old = new QStandardItemModel(min, 14, this); //ui->table_old_db->setColumnCount(14); QStringList headers; //Sets headers in tables headers << "RES-1" << "CAP-1" << "RES-2" << "CAP-2" << "RES-3" << "CAP-3" << "RES-4"<< "CAP-4"<< "RES-5"<< "CAP-5"<< "RES-6"<< "CAP-6"<< "TEMP-RAW"<< "TEMP-ENG"; model_old->setHorizontalHeaderLabels(headers); ui->table_old_db->setModel(model_old); int fila=0; //creo las posiciones necesarias para las compensaciones para que asi no se salgo por error fill_all(); for (int j=0;j<min;j++){ for(int col = 0; col < 14; col++){ QModelIndex index = model_old->index(j,col,QModelIndex()); // 0 for all data if((col % 2) == 0){ //resistivos model_old->setData(index, QString::number(database->get_data_all_nodes_old()[fila][j].get_raw_resis())); }else{ model_old->setData(index, QString::number(database->get_data_all_nodes_old()[fila][j].get_eng_capa())); fila++; if(fila > 6){ fila=0; } } if(col == 12){ model_old->setData(index, QString::number(database->get_data_all_nodes_old()[6][j].get_raw_tempe())); }else if(col == 13){ model_old->setData(index, QString::number(database->get_data_all_nodes_old()[6][j].get_eng_tempe())); } } }
-
@marango27
How can we answer this? How expensive isdatabase->get_data_all_nodes_old()
orget_raw_resis()
etc.? We don't know whether that takes a nanosecond or a minute? Ifdatabase->get_data_all_nodes_old()
is expensive, why not pre-calculate that outside the loop since it's constant? When do you execute this code? Since you are creating a brand new model and attaching a table view each time, why don't you first fill the model with all the data and only do theui->table_old_db->setModel(model_old);
at the end, in case that is taking time to update with all the data changed signals flying around? How long does the model filling take, excluding any table view?