void Dialog::on_pushButton_clicked(){ char *tar2="/home/eugenes/111"; char target[FILENAME_MAX]; int fd; int wd; /* watch descriptor */ ui->listWidget->insertItem(0, QString("!!!Watching")); strcpy (target, tar2); fd = inotify_init(); wd = inotify_add_watch (fd, target, IN_ALL_EVENTS); fd = inotify_init(); while (1) { get_event(fd, target); }}void Dialog::get_event (int fd, const char * target){ ssize_t len, i = 0; char action[81+FILENAME_MAX] = {0}; char buff[BUFF_SIZE] = {0}; len = read (fd, buff, BUFF_SIZE); while (i < len) { struct inotify_event *pevent = (struct inotify_event *)&buff[i]; char action[81+FILENAME_MAX] = {0}; if (pevent->len) strcpy (action, pevent->name); else strcpy (action, target); if (pevent->mask & IN_ACCESS) strcat(action, " was read"); if (pevent->mask & IN_ATTRIB) strcat(action, " Metadata changed"); if (pevent->mask & IN_CLOSE_WRITE) strcat(action, " opened for writing was closed"); if (pevent->mask & IN_CLOSE_NOWRITE) strcat(action, " not opened for writing was closed"); if (pevent->mask & IN_CREATE) strcat(action, " created in watched directory"); if (pevent->mask & IN_MODIFY) strcat(action, " was modified"); if (pevent->mask & IN_OPEN) strcat(action, " was opened"); if (pevent->len) printf ("name=%s\n", pevent->name); ui->listWidget->insertItem(0, QString(action)); i += sizeof(struct inotify_event) + pevent->len; }} /* get_event */