PDA

View Full Version : QAbstractItemModel subclass for a treeview



pvdk
24th June 2008, 15:40
Hello,

I am currently working on a frontend for the "ls" command. I supply the -R command-line argument so it's QProcess output is recursive: that means it's output looks like this:

.:
lol.bat
file1.txt
file2.txt
file3.txt
./usr/

./usr:
textfile.txt
otherfolder/

./usr/otherfolder:
textfile2.txt

I want this output to be viewed in a QDirView-like way, in a treeview. A QAbstractItemModel subclass seemed to be the best solution. On the Trolltechs website I found example code: Simple Tree Model. This code is implemented in my project but now I'm wondering how to properly modify this code to suit my needs.

Currently every time my QProcess emits the readyReadStandardOutput signal a new TreeModel gets constructed with the output of from the QProcess. I strongly feel this is not the best solution. Here's a snippet from my code:


void MainWindow::ViewDirReadStandardOutput()
{
TreeModel *model = new TreeModel(ls->readAll());
treeServer->setModel(model);
}


The Simple Tree Model example can be found here: http://doc.trolltech.com/4.4/itemviews-simpletreemodel.html

I'm quite new to Qt, this is my first application and I really hope someone can help me out with this.

Best regards,
pvdk.

jpn
24th June 2008, 16:53
Isn't QFileSystemModel suitable for you?

pvdk
25th June 2008, 01:13
Isn't QFileSystemModel suitable for you?

I whish it was but the output from ls is actually from a remote machine, trough SSH. Thanks anyway :)