PDA

View Full Version : Custom Model Help PLz



Simz
15th August 2007, 19:24
Hi, i need help with my custom model( from http://www.qtcentre.org/forum/f-qt-programming-2/t-help-with-getting-my-custom-model-working-8296.html )

My listview is always empty...

The bugged model = RemoteModel

jpn
15th August 2007, 22:02
Please, next time you attach a test project, make sure it at least compiles. Also, please try to be more specific with problem description. I can see more than one list view in your application.

The problem does not lie within RemoteModel but in the way it's being used:


void MainWindow::addToList(const QUrlInfo & urlInfo) {
...
// ftp_model->setData(ftp_model->index(-1), &addMe); // <-- WRONG
ftp_model->setData(ftp_model->index(0), QVariant::fromValue(addMe));
...
}

Simz
16th August 2007, 15:05
Thank very much... but my list still empty :)

I've post a compilable project.

The empty list is called lstFileRemote ( le right treeview )
The bugged model RemoteModel
The List is populated in this method (from a ftp connection) :




void MainWindow::addToList(const QUrlInfo & urlInfo) {
RemoteModel::FileList addMe;
addMe.name = urlInfo.name();
addMe.size = QString::number(urlInfo.size());
ftp_model->insertRows(0, 1);
ftp_model->setData(ftp_model->index(-1), QVariant::fromValue(addMe));
}

jpn
16th August 2007, 15:28
Take a closer look at the changes. Do not set data at index -1 but at index 0.