PDA

View Full Version : QTable - Date Base Problem



esq
23rd May 2007, 01:28
Hello,
I need little help. I am writeing a small library data base using QT Designer. And I got a problem. I don't know how to load data from file to QTable object that I've got on my form. Example file:
cell_01;cell_02;cell_03;cell_04
cell_05;cell_06;cell_07;cell_08
cel1_09;cell_l0;cell_11;cell_12
cell_13;cell_14;cell_l5;cell_l6
etc...
And I want to load this into my QTable object so that will look like that:
http://img255.imageshack.us/img255/2291/qtra9.jpg

Please, help me.
esq

ball
23rd May 2007, 02:03
Please use QTableView and QSqlQueryModel instead. It is very easy to use.

esq
23rd May 2007, 02:59
The problem is that I can't use QSqlQueryModel at all. I have to build data base without using any SQL librarys which is lame, I know. This is a shool project...

darksaga
23rd May 2007, 03:25
just use QTableView & subclass QAbstractTableModel as your model.
Look here (http://doc.trolltech.com/4.0/model-view-programming.html) how to do exactly.

inside your model you can use any kind of datastructure you want:



QVariant MyTableModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();

if (role == Qt::TextAlignmentRole)
{
return int(Qt::AlignRight | Qt::AlignVCenter);
}
else if(role == Qt::ToolTipRole)
{
return "hello"; // for example
}
else if (role == Qt::DisplayRole)
{
return myData[index.row()][index.column()]; // for example
}
return QVariant();
}

esq
23rd May 2007, 03:32
sry, I didn't mention that I'm writing in qt3, but tnx so much!