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 :
{
}
break;
case 1:
{
ret = msg.flags();
}
break;
case 2 :
{
//ts = ts.addMSecs(1000 * msg.timestamp().tv_usec);
ret = ts;
}
break;
case 3 :
{
ret = msg.length();
}
break;
case 4 :
{
}
break;
default :
break;
}
}
}
return ret;
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;
To copy to clipboard, switch view to plain text mode
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 :
{
ret = str.setNum(msg.id(), 16).toUpper();
}
break;
case 1:
{
ret = str.setNum(msg.flags(), 16).toUpper();
}
case 0 :
{
QString str;
ret = str.setNum(msg.id(), 16).toUpper();
}
break;
case 1:
{
QString str;
ret = str.setNum(msg.flags(), 16).toUpper();
}
To copy to clipboard, switch view to plain text mode
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
Bookmarks