I want to make a find utility for Windows using Qt. I have created the same application in C# and .NET and I want to make a comparison. My application will have to use QDir::entryList
recursively to find the contents of the specified path and add them to a QListWidget
. Because the entryList maybe slow , it have to run in a QThread
. In addition the user should not await for a long time to see some results but the QListWidget
should be populated with some results.
I have done the following:
sendItem(QString)
when it finds a file. f.moveThread(&thread)
where f
is an object of the find class. wrapper
that has a slot addItem(QString)
an object of this class is executed in the GUI thread so when receives the message sendItem
the slot addItem
does the following l.addItem(s)
where s
is the data that is transmitted with sendItem
signal. Is this the optimal way to update a QListWidget from another thread? Because it is very complicated, (and it does not work) but I do not know a better one. In C# I just created a delegate FillList
I put in a delegate object a method fillList
. I just gave a BeginInvoke
and from within the fillList
method I called this.Dispatcher.invoke
using as an argument the addItem
method of wpf listbox. You can see the C# application in sourceforge.net
And other question: Is it preferable to use the QListView
for this kind of application?
Thanks for the answer.
This is the Qt way of updating GUI from another thread. Since yours does not work out, I think you can paste some code, and we'll analyse.
If you list is not too large, QListWidget is OK, but if your list is very big, then better use QListView, because for QListWidget, each item rendered in the list is itself a widget, which will take a lot of memory. But in QListView, it is the delegate of the view responsible for drawing all the items.