<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Feb 17, 2016 at 7:40 AM, Willem Ferguson <span dir="ltr"><<a href="mailto:willemferguson@zoology.up.ac.za" target="_blank">willemferguson@zoology.up.ac.za</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">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.<br>
<br>
C++ CODE:<br>
    d_importedModel = new DiveImportedModel(this);<br>
    clear_table(&downloadTable);<br>
    printf("** # columns = %d\n",d_importedModel->columnCount());<br></blockquote><div></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
    printf("** Title of 1st column = %s\n",(d_importedModel->headerData(0, Qt::Horizontal, Qt::DisplayRole)).toString().toLatin1().data());<br></blockquote><div><br></div><div>please, use qDebug() <br></div><div>qDebug() << "Columns = " << d_importedModel->columnCount();<br></div><div>qDebug() << "Title of 1st column = " << d_importedModel->headerData(0, Qt::Horizontal)).toString();<br><br></div><div>easier to read. :)<br><br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
QHash<int, QByteArray> roleValues = d_importedModel->roleNames();// *************** here I get the roles.<br>
    printf("** # items in hash = %d\n",roleValues.size());<br>
    QHashIterator<int, QByteArray> i(roleValues);<br>
    int j = 1;<br>
    while (i.hasNext()) {<br>
        i.next();<br>
(1)        QByteArray ba = i.key();<br>
(2)        printf("** %d - (%d) ",j++,(i.key()).length());<br>
    }<br>
<br>
OUTPUT:<br>
** # columns = 3<br>
** Title of 1st column = Date/time<br>
** # items in hash = 6<br>
** 1 -<br>
** 2 -<br>
** 3 -<br>
** 4 -<br>
** 5 -<br>
** 6 -<br>
<br>
WARNINGS/ERRORS:<br>
(1) note: initializing argument 1 of ‘QByteArray::QByteArray(const char*, int)’<br>
     QByteArray(const char *, int size = -1);<br>
<br>
(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());<br>
<br>
>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.<br>
<br>
My questions:<br>
1) In the above, how do I visualise the existing roles?<br></blockquote><div><br></div><div>you don't really see the roles on QML. I usually prefer to do a different thing:<br></div><div>create a DiveComputerObjectHelper : public QObject, export it's properties.<br></div><div>create the model with only one role: DiveComputerObjectHelper* and export only that to the roles, name it 'divecomputer'<br><br></div><div>then on the qml side:<br><br></div><div>model : my_dc_models;<br><br></div><div>delegate : Rectangle {<br></div><div>      Text {<br></div><div>            <a href="http://divecomputer.name">divecomputer.name</a> // here the divecomputer is the model.currentIndex.divecomputer, easily accessible.<br></div><div>      }<br></div><div>}<br></div><div><br><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
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?<br>
Kind regards,<br>
willem<br>
<br>
<br>
_______________________________________________<br>
subsurface mailing list<br>
<a href="mailto:subsurface@subsurface-divelog.org" target="_blank">subsurface@subsurface-divelog.org</a><br>
<a href="http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface" rel="noreferrer" target="_blank">http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface</a><br>
</blockquote></div><br></div></div>