jpn (6th November 2007)
connect clicked(const QModelIndex &) or doubleClicked(const QModelIndex &) signal to slot that setRootIndex ( const QModelIndex & ) for index in first column & the same row as passed in signal...
invictus (7th November 2007)
Speaking of problems...
This is my goTo slot (much like your setRootIndex):
dirView is a QTreeView. The problem is that when the up method is run (which run goTo() with the parent() of the dirView rootIndex like in your example) the program just quits/crashes. If I comment the if(dirView->isDir()) line it works.void goTo(const QModelIndex &dir)
{
if(dirModel->isDir(dir))
{
dirView->setRootIndex(dir);
addressField->setText(dirModel->filePath(dir));
upAction->setEnabled(dir.isValid());
}
}
Last edited by invictus; 7th November 2007 at 22:10.
Did you notice that I modified the statement which enables/disables "upAction" in the example from
toQt Code:
upAction->setEnabled(listView->rootIndex().isValid());To copy to clipboard, switch view to plain text mode
? The former works on Windows but not on Linux. On Linux, I experienced the same crash youre' talking about. The latter should work on both environments. Unfortunately I don't have a Mac so I don't know for sure if there's any pitfalls on that matter but I believe the latter should take care of it on Mac too..Qt Code:
upAction->setEnabled(!dirModel->fileInfo(listView->rootIndex()).isRoot());To copy to clipboard, switch view to plain text mode![]()
J-P Nurmi
Yeah, but its on the isDir() that it crashes. I am using windows btw.
Perhaps the problem is that on Windows there is another level above the root ? its a list of partitions like "C:", "D:", etc...
To me this suggests that goTo() get called with an invalid index and QDirModel is missing sufficient checks. Does the example crash too?
J-P Nurmi
Drives are "root" on Windows:
Notice that QDirModel::isDir() is basically a shortcut for QDirModel::fileInfo().isDir(). Also, calling QDirModel::fileInfo() or QDirModel::isDir() throws an assert when passed an invalid index:Qt Code:
To copy to clipboard, switch view to plain text mode
So you will have to take care of it yourself that you don't call QDirModel::fileInfo() or QDirModel::isDir() with an invalid index.Qt Code:
QDirModel model; model.fileInfo(index.parent()); // "ASSERT: "d->indexValid(index)" in file itemviews\qdirmodel.cpp"To copy to clipboard, switch view to plain text mode
J-P Nurmi
Hi,
i had similar problems, when i was writing dirModel with Desktop myComputer & MyDocuments on top level and i'm quite sure that jpn has right there's no bugs on qt and errors you got are caused by passing unexisting modelIndexes to model...
try to check hasIndex() for each QModelIndex you are using - it might be useful to find the error.
hello.// how an i load the files from the file list so that i an get its directory to load the file itself to transfer it to another device..thanks!
Hi I'm doing that thing with the contents of clipboard.. ( a simple enumeration )
const QMimeData *mime = QApplication::clipboard()->mimeData();
if (mime && mime->hasUrls()) {
QStringList fileList;
foreach(QUrl url, mime->urls())
fileList.append(url.toLocalFile());
........
But If clipboard was filled by a windows application I can't know if I I need to copy or cut ..... do you know a trick ????
Bookmarks