Using QTreeView to compare two directories
-
I am a newbie with Qt here.. but can I use QTreeView to create a comparison between two similiar directories including its subdir matching those with the same file name, and leaving those that does not have the same file name.
Which UI should I use best to achieve this?
Thanks in advance.
-
I don't understand the question.
A tree view (as any other item view class) is for displaying data, not for analyzing it.
You will have to make an algorithm for collecting the data (compare the two trees and decide which files and dirs should stay and which not). Then choose the item view that fits your needs. You may store the results of the comparison in your own item model or use one of the standard models provided by Qt. Which one is better, depends on the actual use case.
-
Here is an example:
dir1 has 4 files and 1 directory named:
a.exe,
a copy.exe,
b.exe
c.exe
boson (a directory that has 2 files: x.exe, and y.exe)dir2 has 2 files and 2 directory named:
a.exe
c.exe
e.exe
boson (a directory 1 file: x.exe)
boson2 (a directory 1 file: z.exe)I would like a result in form of table
dir1 | dir2
boson | boson
----- x.exe | x.exe
----- y.exe | (null)
(null) | boson2
----- (null) | z.exe
a.exe | a.exe
a copy.exe | (null)
b.exe | (null)
c.exe | c.exe
(null) | e.exeThis is something like WinMerge view.. you compare files with same name on 2 different directories. I was wondering which model best to use? I am a newbie so I prefer standard model if possible.
-
You will have to populate the model yourself. For a first try, I would go with a [[Doc:QStandardItemModel]] and store the file name and possibly path in one of the user properties. You'll have to "calculate" the contents yourself though.
To ease the learning of Qt, I recommend studying the introductions and examples. For the model/view programming, you should read the more detailed guides too, even if you're not going to implement your own model at the moment. And make you some simple pet project to get accustomed to the API.
For displaying the data- you have different options here: Two tree views, one for each directory - you will have to fill in dummy items for the missing files and directories then. Or a table view. But that has no nice hierarchy, though. I think you'll need to experiment a bit here.