zoukankan      html  css  js  c++  java
  • 22.监视文件

    • mainwindow.h
       1 #ifndef MAINWINDOW_H
       2 #define MAINWINDOW_H
       3 
       4 #include <QMainWindow>
       5 #include <QFileSystemWatcher>
       6 #include <QLabel>
       7 
       8 namespace Ui {
       9 class MainWindow;
      10 }
      11 
      12 class MainWindow : public QMainWindow
      13 {
      14     Q_OBJECT
      15 
      16 public:
      17     explicit MainWindow(QWidget *parent = 0);
      18     ~MainWindow();
      19 
      20 private slots:
      21     void directoryChanged(QString path);
      22 
      23 private:
      24     Ui::MainWindow *ui;
      25     QFileSystemWatcher fsspy;
      26     QLabel *label;
      27 };
      28 
      29 #endif // MAINWINDOW_H
    • mainwindow.cpp
       1 #include "mainwindow.h"
       2 #include "ui_mainwindow.h"
       3 #include <QMessageBox>
       4 #include <QDir>
       5 #include <QVBoxLayout>
       6 #include <QDebug>
       7 
       8 MainWindow::MainWindow(QWidget *parent) :
       9     QMainWindow(parent),
      10     ui(new Ui::MainWindow)
      11 {
      12     ui->setupUi(this);
      13 
      14     //获取指定目录
      15     QStringList args = qApp->arguments();
      16     QString path;
      17     if(args.count()>1)
      18     {
      19         path=args[1];
      20     }
      21     else
      22     {
      23         path = QDir::currentPath();
      24     }
      25 
      26     label = new QLabel(this);
      27     label->setText("spypath"+path);
      28     QVBoxLayout *layout = new QVBoxLayout(this);
      29     layout->addWidget(label);
      30     qDebug() << path;
      31     fsspy.addPath(path);
      32     connect(&fsspy,SIGNAL(directoryChanged(QString)),this,SLOT(directoryChanged(QString)));
      33 }
      34 
      35 MainWindow::~MainWindow()
      36 {
      37     delete ui;
      38 }
      39 
      40 //触发监视
      41 void MainWindow::directoryChanged(QString path)
      42 {
      43     QMessageBox::information(NULL,"changes",path);
      44 }
  • 相关阅读:
    css基础1
    js基础
    定位与浮动
    最新学习
    前端初学第一天
    js2
    js1
    html加css
    js三元表达式
    java script的学习
  • 原文地址:https://www.cnblogs.com/xiaochi/p/8757931.html
Copyright © 2011-2022 走看看