View Full Version : How to show the drive size in QDirModel

18th November 2014, 03:54
hello everyone,
I want to show the drive size in QDirModel. I try to rewrite the "SetData" function, but the parameter "value" is a quote, I cant change its value. how can I do it ? thanks.

setData: setData(const QModelIndex &index, const QVariant &value, int role)


18th November 2014, 06:29
What do you mean by -

but the parameter "value" is a quote

The parameter value is const in the arguments and you wont be able to change its value inside the function.

But you can always pass data to it right...

QVariant var = 23;
model->setData(index, var, role); :rolleyes:

19th November 2014, 08:17
Thanks your reply.
But have a problem, the drive size in the second column , the setData have not the parameter "column". I want to show the drive size in the second column and how can I do it. thanks.

oh, I see. I try .thanks.

Added after 1 14 minutes:

I use this:

and in setData function:

QString driveName = index.data().toString();
QModelIndex child;
if (driveName.length() > 1 && driveName.at(1) == QLatin1Char(':'))
qDebug() << "set drive size";
child = QDirModel::index(index.row(), 1, index);
setData(child, value,role);
emit dataChanged(index, index);
return true;

but it not effect. how can I do it? thanks.