Reimplementing QFileSystemModel Checkboxes using QMap inconsistent results
-
@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.
-
@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. -
@mrjj It only has this behavior when I use QMap if I do this with QSet everything works fine. That's what I don't get
-
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.
-
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.
-
@mrjj this is absolutely not normal. It' a for loop iterating from 0 to rowCount(parent). Then it uses model->index(i, 0, parent). So this is not possible to output twice the same file.
-
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.