Reimplementing QFileSystemModel Checkboxes using QMap inconsistent results
-
@JonB
Very good question, but i think it will return a QVariant constructed from the
int checked variable. Else compiler should be very unhappy if no automatic
conversion can happen. -
I am supposed to return a Qt::CheckState elem from enum which is int.
Yes the compiler constructs a QVariant from the int value.
So, any idea about what's going wrong here ?
-
Any help please
-
@moffa13
Add some qDebug() statement to see what index are sent and what it set pr index.
I think its one of those cases where debugger and tools are more useful than guessing looking at code. -
@mrjj said in Reimplementing QFileSystemModel Checkboxes using QMap inconsistent results:
@moffa13
Add some qDebug() statement to see what index are sent and what it set pr index.
I think its one of those cases where debugger and tools are more useful than guessing looking at code.If it was that simple I wouldn't have asked.
qDebug is showing me correct paths before calling setData. The problem is that for whatever reason, some checkboxes won't get checked. I almost always get a different result whenever I run this code.
qDebug in setData tells me that the function receives Qt::Checked but it's not the case.
-
@moffa13
Hi
Hmm, i would suspect the QSet<QPersistentModelIndex>
could contain incorrect indexes.
Im wondering if QFileSystemModel might invalidate QPersistentModelIndexes i have seen with QSqlTableModel. -
@moffa13
Hmm. yes that is odd.
One difference with Set/QMap is if u ask QMap for non existing value
a default-constructed value is returned but you seem to check with contains so
should not happen? -
Yeah, exactly, for me it should work.
However I noticed something which may be useful. I added a QEventLoop when doing setData to look for the dataChanged signal but when I do this and I use qDebug to show the files returned by model::index, I get something like this :
Normal dir is
a.txt
b.txt
c.txtfilePath in the loop returns this :
a.txt
b.txt
b.txtAnd c.txt does not get checked which is also odd.
-
@moffa13
Hmm. you know how b.txt is included twice ? -
@moffa13
Could you try to do the same for loop from say a button and use
no localEvent loop or anything like that and see if its
reproducible in other context ? -
Ok I found what was causing this awful bug.
When I check if the map contains the index, I actually check the raw index not the QPersistantModelIndex so this is not the same object and I think qmap does not check equality using == operator .
So I have to iterate over the map and check using QPersistantModelIndex "==" operators which can compare from a QModelIndex.
12/15