PDA

View Full Version : QMap model data



gyre
9th December 2007, 20:13
Hi...Im trying to imeplement a model that would store some statistics
I wanted to use QMap to store count as a value of QMap item under a certain key...
The problem is that I dont know ho to implement a data() method of the model to get the data from actual index...since the QMap doesnt store the data as they are inserted into it but it stores the data by the keys...
So QMap is no use in this...
Can anyone advised me what would be the best to do this ?
Thanks

gyre
9th December 2007, 20:27
I need to implement something like this...


QVariant MsgStatsModel::data(const QModelIndex &index, int role) const
{

QVariant ret;

if(!index.isValid()){
std::cout <<"Invalid Index of data provided!"<< std::endl;
return ret;
}

int row = index.row();
int col = index.column();

if(row >= 0 && row < rowCount()) {
if(role == Qt::DisplayRole) {
//get the OBJECT stored on "row"
switch(col) {
case 0 :
ret = QVariant(/*HERE THE ID MUST BE RETURNED*/);
break;
case 1:
ret = QVariant(/*HERE THE COUNT OF THE ID MUST BE RETURNED*/);;
break;
}
}
}
return ret;
}

gyre
9th December 2007, 20:35
Hm as I see it...the only chance to do this statistcs thing is using the QList of QMaps

gyre
9th December 2007, 22:19
Hi I tried to implement the model as I wrote above...
But it somehow doesnt work and I dont know why :(
Can anyone please tell me what Im doing wrong ?
Or whats the best way to implement in Qt a statistics model that would store a count value(of received messages) under a key(id of concrete message) ?
my codes are in attachement...
ThAnks