QML TableView questions

Willem Ferguson willemferguson at zoology.up.ac.za
Wed Feb 17 01:40:31 PST 2016


I am using the existing class DiveImportedModel to adapt the existing 
code for mobile use. I use a TableView QML item to view the data but it 
apperas that QML hates the existing model that is aimed at a QTableView 
widget. I suspect this is because the roles have not been defined 
appropriately for the QML. So I am trying to access the existing roles 
and I cannot.

C++ CODE:
     d_importedModel = new DiveImportedModel(this);
     clear_table(&downloadTable);
     printf("** # columns = %d\n",d_importedModel->columnCount());
     printf("** Title of 1st column = 
%s\n",(d_importedModel->headerData(0, Qt::Horizontal, 
Qt::DisplayRole)).toString().toLatin1().data());
QHash<int, QByteArray> roleValues = d_importedModel->roleNames();// 
*************** here I get the roles.
     printf("** # items in hash = %d\n",roleValues.size());
     QHashIterator<int, QByteArray> i(roleValues);
     int j = 1;
     while (i.hasNext()) {
         i.next();
(1)        QByteArray ba = i.key();
(2)        printf("** %d - (%d) ",j++,(i.key()).length());
     }

OUTPUT:
** # columns = 3
** Title of 1st column = Date/time
** # items in hash = 6
** 1 -
** 2 -
** 3 -
** 4 -
** 5 -
** 6 -

WARNINGS/ERRORS:
(1) note: initializing argument 1 of ‘QByteArray::QByteArray(const 
char*, int)’
      QByteArray(const char *, int size = -1);

(2) error: request for member ‘length’ in ‘i.QHashIterator<Key, 
T>::key<int, QByteArray>()’, which is of non-class type ‘const int’  
printf("** %d - (%d) ",j++,(i.key()).length());

 From the above it is clear that a valid importedModel object is 
created. BUT: messages above indicate that the key() method of QHash 
returns an INTEGER, not a QByteArray.

My questions:
1) In the above, how do I visualise the existing roles?
2) Within the broader QML context, where should one synchronise the 
roles with the existing heading titles? Could one do it in a similar way 
to the headerData() method of the QAbstractTableModel by using 
re-implementing the roleNames() method?
Kind regards,
willem




More information about the subsurface mailing list