开发者

Which Qt classes use the disk directly?

I'm trying to write a library to separate all the disk activity out into its own thread, but the documentation doesn't really care about such things.

What I want to accomplish 开发者_如何学运维is that aside from startup, all disk activity is asynchronous, and for that, I need to wrap every class that accesses the disk. Here's what I found so far:

QtCore:

  • QFile
  • QTemporaryFile
  • QDir
  • QFileInfo
  • QFileSystemWatcher
  • QDirIterator
  • QSettings

QtGui:

  • QFileDialog
  • QFileSystemModel
  • QDirModel

I'm sure there are more.


I have a couple of points -

First, when you do this, remember that all GUI objects are based on QWidget, have run in the start-up thread. See http://doc.trolltech.com/4.6/threads-qobject.html which talks about threading. The quote is "Although QObject is reentrant, the GUI classes, notably QWidget and all its subclasses, are not reentrant. They can only be used from the main thread. As noted earlier, QCoreApplication::exec() must also be called from that thread".

This also means that if you need to display information from one of these wrapper classes on the screen, you need to be careful about ownership of objects when you pass information back to the GUI thread. Particularly, anything that is based on QObject.

Second, starting threads carries a run-time cost. So I would suggest that you structure your design to minimize the number of times this wrapper thread class is created and destroyed.

Overall an interesting approach to files. This is one that I'm going to consider for my current application. It may solve some problems I'm having.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜