PDA

View Full Version : QFileSystemWatcher empty QStringList file()



Carmengg
29th January 2014, 11:07
Hi everyone. I'm new here and I hope that someone can help me. I don't know what I'm doing wrong. My problem is that I am referring to a directory with 10 files but the function files() of QFileSystemWatcher class give me back a empty list. That's my code:

UploadDeleteFile.hpp



#ifndef UPLOADDELETEFILE_HPP_
#define UPLOADDELETEFILE_HPP_

#include "TestScheduler.hpp"
#include "accountInfoSettings.hpp"
#include <QFileSystemWatcher>
#include <QObject>
#include <QStringList>

class UploadDeleteFile : public QObject{

Q_OBJECT

public:
UploadDeleteFile(QObject *parent, TestScheduler *myTestScheduler, accountInfoSettings *myAccountInfoSettings);
virtual ~UploadDeleteFile();

QStringList getFileNameList();
Q_INVOKABLE void setFileNameList();

accountInfoSettings *accountInfo;
QFileSystemWatcher fileSystem;
TestScheduler *testScheduler;
QStringList filelist;
QString filename;
int index;
};

#endif /* UPLOADDELETEFILE_HPP_ */



UploadDeleteFile.cpp



#include "FileUploader.hpp"
#include "MessageComposer.hpp"
#include "UploadDeleteFile.hpp"

#include <bb/system/SystemToast>
#include <stdio.h>

using namespace bb::cascades;
using namespace bb::pim::account;
using namespace bb::system;

UploadDeleteFile::UploadDeleteFile(QObject *parent, TestScheduler *myTestScheduler, accountInfoSettings *myAccountInfoSettings): QObject(parent) {
// TODO Auto-generated constructor stub
testScheduler = myTestScheduler;
accountInfo = myAccountInfoSettings;
index = -1;
filename = "";
filelist = QStringList();
}

UploadDeleteFile::~UploadDeleteFile() {
// TODO Auto-generated destructor stub
}

void UploadDeleteFile::setFileName(QString name){
filename = name;
}

void UploadDeleteFile::setFileNameList(){
fileSystem.addPath("data/Tests/");
QStringList directories = fileSystem.directories();
filelist = fileSystem.files();
}

QStringList UploadDeleteFile::getFileNameList(){
return filelist;
}


Any help is welcome. Thanks Carmen

anda_skoa
29th January 2014, 12:51
You are not watching any files, only the directory "data/Tests/".

Cheers,
_

Carmengg
30th January 2014, 07:57
Could you give me more info? My files are in "data/Tests/" directory. I only need to read their names.
Thanks to replay me :)

anda_skoa
30th January 2014, 08:49
Could you give me more info?


The file system watcher can be told to watch files and directories. You are only watching a directory, thus files() returns an empty list.



My files are in "data/Tests/" directory. I only need to read their names.

Maybe you are looking for QDir::entryList)()?

Cheers,
_

Carmengg
30th January 2014, 10:57
Thank you soooo much. That works :)