PDA

View Full Version : Display files one by one for particular directory - Just like antivirus scanning.



Gurpreet
21st July 2012, 12:40
Hi! Experts

I am making an application ....

Using Browse button I select path of particular directory after clicking on the start button selected path shows in line edit and the files are shown in line edit one by one instead of list widget at one go. All the file names are displayed of that directory one by one after some duration.Displaying the files shoud be similar to anti-virus scanning software.

My code for viewing in list widget is as follows...


connect(browse,SIGNAL(clicked()),this,SLOT(find()) );

void MainWindow::find()
{
QString dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"),"/home",QFileDialog::ShowDirsOnly| QFileDialog::DontResolveSymlinks);
QDir lsdir(dir);
l->setText( dir );
lw->addItems(lsdir.entryList());
}

wysota
21st July 2012, 12:58
What do you mean "one by one"? Doesn't the code you posted do that already?

Gurpreet
21st July 2012, 13:36
mean of one by one is that second file must be shown after a one second of first file shown..

wysota
21st July 2012, 14:20
mean of one by one is that second file must be shown after a one second of first file shown..

Hmmm.... why? :)


class InsertToListDelayer : public QObject {
Q_OBJECT
public:
InsertToListDelayer(QStringList items, QListWidget *list, int delay = 1000, QObject *parent = 0) : QObject(parent) {
m_items = items;
m_list = list;
m_delay = delay;
m_timer = -1;
}
public slots:
void start(int delay = -1) {
if(delay > 0) m_delay = delay;
m_timer = startTimer(m_delay);
}
void stop() {
if(m_timer != -1) { killTimer(m_timer); m_timer = -1; }
}
signals:
void finished();
protected:
void timerEvent(QTimerEvent *te) {
m_list->addItem(m_items.takeFirst());
if(m_items.isEmpty()) {
stop();
emit finished();
}
}
private:
int m_timer, m_delay;
QStringList m_items;
QListWidget* m_list;
};


InsertToListDelayer *del = new InsertToListDelayer(lsdir.entryList(), lw, 1000, this);
del->start();
connect(del, SIGNAL(finished()), del, SLOT(deleteLater()));