> I strongly object to using a thread for something this simple. Threading > is to be avoided whenever possible, because it's so hard to debug. Use
There's no black magic involved in threads. Though I agree it might be an overkill in some cases, not so sure about this case. > the chunks method instead. Something like this: > > class FileLoader : public QObject { > Q_OBJECT > > public: > explicit FileLoader(const QString& fileName) { > m_file(fileName); > m_timer.setSingleShot(false); > m_timer.setInterval(0); > m_timer.start(); > connect(&m_timer, SIGNAL(triggered()), SLOT(readChunk())); > > m_file.open(QIODevice::ReadOnly)); > } > > signals: > void done(const QByteArray& bytes); > void failed(); > void progress(qreal percent); > > private slots: > void readChunk() { > if (!m_file.isOpen()) { > m_timer.stop(); > emit failed(); > } else { > m_bytes.append(m_file.read(1024)); The read/write chunk size needs to be selected with care. The exact answer will depend on the underlying filesystem in use. I think it should not be smaller than the file system block size. -mandeep _______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest