PDA

View Full Version : MODEL/VIEW programming



mira
20th April 2006, 23:03
Hi all,
Can some help me with MODEL/VIEW programming in QT4
I have program for database of humans, and i display small table with katalog of peoples,
I used on this Q3Tab in new widget, and my katalog is stored in container „vector“…
here is link screen my pgm (http://ki.ujep.cz/~minsky/screen.jpg)


void MainWindow::show_table()
{
Tab *tabulka = new Tab;
tabulka->table->setNumRows(people.size());
tabulka->table->setColumnWidth ( 0, 115 );
tabulka->table->setColumnWidth ( 1, 115 );
tabulka->table->setColumnWidth ( 2, 70 );

for( int row= 0; row < people.size() ; row++)
{
tabulka->table->setText(row,0,people[row].surname);
tabulka->table->setText(row,1,people[row].first_name);
tabulka->table->setText(row,2,people[row].number);
tabulka->table->sortColumn(0,TRUE,TRUE);
}
tabulka->table->setReadOnly(TRUE);
tabulka->show();
}

„people“ is container style vector..
But i have to show this my table via MODEL/VIEW programming,
I readed qt-Assistant but i dont know still, how i can make it, pls help me with this
and sory for my bad english

wysota
20th April 2006, 23:32
Hello!

Do you use some kind of SQL database to store the info?

You might want to take a look at Qt examples about model-view programming and reference for classes like QTableView, QAbstractItemModel and QSqlTableModel.

If you have any doubts, feel free to ask.

mira
21st April 2006, 11:07
@wysota
I didnt use some kind of SQL database, i stored data into ordinary *.txt file, but i mean that this in not important!!!
I have stored data in program in vector container (from C++) hier it is names "people".
I readed assistant with examples here model/view programming (http://doc.trolltech.com/4.1/model-view-programming.html), but no one directly working with table. maybe this "chart" (http://doc.trolltech.com/4.1/itemviews-chart.html)
my general problem is that i have table in new widget, not in mainwidow pgm

wysota
21st April 2006, 11:19
I didnt use some kind of SQL database, i stored data into ordinary *.txt file, but i mean that this in not important!!!

It is important, because if you used SQL, you could use one of existing sql-based models Qt4 provides.


I have stored data in program in vector container (from C++) hier it is names "people".
I readed assistant with examples here model/view programming (http://doc.trolltech.com/4.1/model-view-programming.html), but no one directly working with table. maybe this "chart" (http://doc.trolltech.com/4.1/itemviews-chart.html)
my general problem is that i have table in new widget, not in mainwidow pgm

If your model is simple, you can subclass QStandardItemModel (or use it directly). And then just set the model to QTableView and you're done. If your model is complex you should subclass QAbstractTableModel.