Qt实现实时监控文件夹状态-创新互联
####Qt实现 实时监控文件夹状态:文件夹内容增删、重命名、删除等
专注于为中小企业提供网站建设、成都网站建设服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业白云免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了1000多家企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。//重建服务器请求监测类
#ifndef QRECONREQUESTLISTENER_H
#define QRECONREQUESTLISTENER_H
#include
#include
class QFileSystemWatcher;
class QReconRequestMonitor : public QObject
{
Q_OBJECT
public:
QReconRequestMonitor( const QString& strDirectory );
~QReconRequestMonitor();
signals:
void sigCommitReconRequest( const QString& strFilePath );
protected slots:
void slotDirectoryChanged( const QString& strDirectory );
private:
QStringList GetFileNames( const QFileInfoList& fileInfoList );
private:
QString m_strMonitorDirectory;
QStringList m_strListFileNames;
QFileSystemWatcher* m_pDirectoryWatcher;
};
#endif // QRECONREQUESTLISTENER_H
#include "QReconRequestMonitor.h"
#include
#include
#include
QReconRequestMonitor::QReconRequestMonitor( const QString& strDirectory )
{
m_strListFileNames.clear();
m_strListFileNames = QDir( strDirectory ).entryList();
m_strMonitorDirectory = strDirectory;
m_pDirectoryWatcher = new QFileSystemWatcher( this );
m_pDirectoryWatcher->addPath( strDirectory );
connect( m_pDirectoryWatcher, SIGNAL( directoryChanged( const QString& ) ), this, SLOT( slotDirectoryChanged( const QString& ) ) );
}
QReconRequestMonitor::~QReconRequestMonitor()
{
m_strListFileNames.clear();
}
void QReconRequestMonitor::slotDirectoryChanged( const QString& )
{
QStringList strListFileNames; //To save new file names
QFileInfoList fileInfoList = QDir( m_strMonitorDirectory ).entryInfoList();
for( int n = 0; n < fileInfoList.size(); n++ )
{
QFileInfo fileInfo = fileInfoList[ n ];
if( fileInfo.fileName().compare( "." ) == 0 || fileInfo.fileName().compare( ".." ) == 0 )
continue;
if( fileInfo.isDir() )
continue;
QString strFileName = fileInfo.fileName();
if( !m_strListFileNames.contains( strFileName ) )
strListFileNames << strFileName;
}
if( strListFileNames.isEmpty() )
{
m_strListFileNames.clear();
m_strListFileNames = GetFileNames( fileInfoList );
return;
}
for( int n = 0; n < strListFileNames.size(); n++ )
{
//commit recon request
QString strFilePath = m_strMonitorDirectory + "/" + strListFileNames[ n ];
emit sigCommitReconRequest( strFilePath );
}
m_strListFileNames.clear();
m_strListFileNames = GetFileNames( fileInfoList );
return;
}
QStringList QReconRequestMonitor::GetFileNames( const QFileInfoList& fileInfoList )
{
QStringList strLstNames;
int nFileNum = fileInfoList.size();
for( int n = 0; n < nFileNum; n++ )
{
QFileInfo fileInfo = fileInfoList[ n ];
strLstNames << fileInfo.fileName();
}
return strLstNames;
}
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
文章名称:Qt实现实时监控文件夹状态-创新互联
文章网址:http://azwzsj.com/article/dipodh.html