qt - QSqlTableModel, QTableView change columns not updated -


i have sql model connects single table, table change number of columns depending on conditions during execution of program. model connected qtableview. have function controls number of columns @ end of function have call model->select(), update information of model , tableview->reset(), thought rearrange view adding or taking away columns. problem view not change original number of columns had. if reduce number can see data change , show empty on missing columns. there command tableview resize self? editing question in constructor of class i'm reading table , setting view:

  header = new qsqltablemodel(parent,data->m_db);   header->settable("c"+qstring::number(marktime.tosecssinceepoch())+"t");   header->select();   ui->heading->setmodel(header);   ui->heading->show(); 

every time that number of columns changed sql procedure change number of columns:

void importprocess::copytable(qstring oldtable, qstring newtable) {   qsqlquery queryold, querynew;   queryold.prepare("select * :oldtable");   queryold.bindvalue(":oldtable",oldtable);   queryold.exec();    if(queryold.record().isempty()==true) return; //old table empty, nothing copy    int oldcolumn=queryold.record().count();    qstring replaceline="insert "+newtable+" values(";   while(queryold.next()==true)     {       replaceline.append(qstring::number(queryold.value(0).toint()));       replaceline.append(", "+queryold.value(1).tostring());       for(int y=0;y<(oldcolumn < ui->columns->value() ? oldcolumn : ui->columns->value());y++)         {           replaceline.append(", "+qstring::number(queryold.value(y+2).tofloat()));         }       replaceline.append(")");       querynew.exec(replaceline);     } } 

then header file updated, , here thought tableview redrawn:

void importprocess::updateheadingtable() {   qsqlquery query;   query.exec("delete c"+qstring::number(marktime.tosecssinceepoch())+"t");   qstring description= ui->week->ischecked() == true ? "week" : "size";   query.exec("insert c"+qstring::number(marktime.tosecssinceepoch())+"t (id, description) values (101, '"+description+"')");   for(int x=0;x<ui->columns->value();x++)     {       query.exec("update c"+qstring::number(marktime.tosecssinceepoch())+"t set col"+qstring::number(x)+" = '30'");     }   header->select();   ui->heading->reset();  } 

i believe forgot protected methods:

void qabstractitemmodel::begininsertcolumns(const qmodelindex &parent, int first, int last); void qabstractitemmodel::beginremovecolumns(const qmodelindex &parent, int first, int last); void qabstractitemmodel::endinsertcolumns(); void qabstractitemmodel::endremovecolumns(); 

every time number of column change should call first or second method. after change should call third or fours method.

you can read these methods in qt documentation.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -