PDA

View Full Version : Model display problem



gyre
31st December 2007, 07:12
Hey!
I have implemented a model...it worked just fine without any problem...
UNTIL one moment :(
Here is the snippet of data() method that specify how the data should be displayed by the view:

if(row >= 0 && row < rowCount()) {
if(role == Qt::DisplayRole) {
const QVcaCanMsg &msg = msgList.at(row);
switch(col) {
case 0 :
{
ret = QVariant((unsigned)msg.id());
}
break;
case 1:
{
ret = msg.flags();
}
break;
case 2 :
{
QDateTime ts = QDateTime::fromTime_t(msg.timestamp().tv_sec);
//ts = ts.addMSecs(1000 * msg.timestamp().tv_usec);
ret = ts;
}
break;
case 3 :
{
ret = msg.length();
}
break;
case 4 :
{
ret = QString(QByteArray((const char*)msg.data(), msg.length()).toHex()).toUpper();
}
break;
default :
break;
}
}
}
return ret;
I have decided instead of displaying int numbers of id(unsigned long) and flags(integer) (returned by id() and flags() methods) to display them hexadecimally...
and thats where the problem occured..
I have changed the previous code to:


case 0 :
{
QString str;
ret = str.setNum(msg.id(), 16).toUpper();
}
break;
case 1:
{
QString str;
ret = str.setNum(msg.flags(), 16).toUpper();
}
now the items added to the model DOES NOT GET DISPLAYED AT ALL.
When I leave the original solution displaying ulong/int numbers everything works just fine...
Anyone has an idea what am I doing wrong ?
Thanks

ps: when I print with the QDebug the value of "str" it gets printed in a correct way - as hexadecimal number of given id/flags

high_flyer
31st December 2007, 10:23
what data type should this function return, a QVariant?

marcel
31st December 2007, 12:40
You already did it ok in the first example. I don't understand why you messed it up in the second. It should be:


case 0 :
{
QString str;
ret = QVariantr(str.setNum(msg.id(), 16).toUpper());
}
break;
case 1:
{
QString str;
ret = QVariant(str.setNum(msg.flags(), 16).toUpper());
}

jpn
31st December 2007, 14:46
Let me inform that the problem was already solved. He was using a proxy model which filtered out everything but integers, thus no hexadecimal numbers were displayed.

PS. gyre, could you pay more attention to the way you jump between this forum and #qt, please? You always ask your questions in both places. People are here to help you for free, for their own willingness. Do not waste their time by leaving here open questions that were already solved elsewhere. Don't act like these two communities didn't know about each other. It feels funny to read on #qt that "a friend of yours advised to do this and that" when it was in fact advised by me myself or someone else on this forum.