QVector<someclass*> vector; QTableView *view = new QTableView(this); TableModel *model = new TableModel(vector, this); view->setModel(model); someclass *data = new someclass; vector.append(data);
QVector<someclass*> vector; QTableView *view = new QTableView(this); view->setModel(model); someclass *data = new someclass; vector.append(data); TableModel *model = new TableModel(vector, this);
vector.append(game); model->insertRow(vector.size()-1);
bool TableModel::insertRows(int row, int count, const QModelIndex & parent = QModelIndex()){ beginInsertRows(parent, row, row+count-1); BaseGame *game; for (int row = 0; row < count; ++row) { game = new BaseGame; gameList->append(game); } endInsertRows(); return true;}
tmGames->insertRow(gameList.size()-1);
C++ (Qt)game = new BaseGame;
bool TableModel::insertRows(int row, int count, const QModelIndex & parent = QModelIndex()){ beginInsertRows(parent, row, row+count-1); endInsertRows(); return true;}
tmGames->insertRows(0, 1, tmGames->index(0, 0));
twGames = new QTableWidget(500, 1, this); QTableWidgetItem *item; QTime time; time.start(); for(int i=0; i<500; i++){ item = new QTableWidgetItem("lol"); twGames->setItem(i, 0, item); } qDebug() << "done!" << time.elapsed();
twGames = new QTableWidget(500, 1, this);
QTime time; time.start(); QTableWidgetItem *item; for(int i=0; i<500; i++){ item = new QTableWidgetItem("lol"); twGames->setItem(i, 0, item); } qDebug() << "done!" << time.elapsed();
class FormBase: public QMainWindow{Q_OBJECTprivate: QTableWidget *twGames;public: explicit FormBase(); void updateGames();};
FormBase::FormBase(){ setMinimumSize(600, 500); twGames = new QTableWidget(500, 1, this); QTableWidgetItem *item; setCentralWidget(twGames);далее все комментируется для теста слота QTime time; time.start(); for(int i=0; i<500; i++){ item = new QTableWidgetItem("lol"); twGames->setItem(i, 0, item); } qDebug() << "done!" << time.elapsed();}void FormBase::updateGames(){ QTime time; time.start(); QTableWidgetItem *item; for(int i=0; i<500; i++){ item = new QTableWidgetItem("lol"); twGames->setItem(i, 0, item); } qDebug() << "done!" << time.elapsed();}
QTime time; time.start(); twGames->model()->blockSignals(1); QTableWidgetItem *item; for(int i=0; i<500; i++){ item = new QTableWidgetItem("lol"); twGames->setItem(i, 0, item); } twGames->model()->blockSignals(0); twGames->reset(); qDebug() << "done!" << time.elapsed();