From e1dbb7db6dce2ef503514357a77616d06f0f190f Mon Sep 17 00:00:00 2001 From: Austen Date: Wed, 18 Jun 2014 21:32:10 -0400 Subject: [PATCH] Attempting QProcess execution --- Picture.pro.user | 2 +- picture.cpp | 28 +++++++-- picture.h | 3 + picture.ui | 153 ++++++++++++++++++++++++++++++----------------- 4 files changed, 123 insertions(+), 63 deletions(-) diff --git a/Picture.pro.user b/Picture.pro.user index 04ea3a6..259c700 100644 --- a/Picture.pro.user +++ b/Picture.pro.user @@ -1,6 +1,6 @@ - + ProjectExplorer.Project.ActiveTarget diff --git a/picture.cpp b/picture.cpp index 43eef75..f269c82 100644 --- a/picture.cpp +++ b/picture.cpp @@ -3,10 +3,21 @@ Picture::Picture(QWidget *parent) : QMainWindow(parent), ui(new Ui::Picture){ ui->setupUi(this); + connect(&commandProcess,SIGNAL(readyReadStandardOutput()),this,SLOT(log())); + connect(&commandProcess,SIGNAL(readyReadStandardError()),this,SLOT(log())); connect(ui->actionOpen_Files,SIGNAL(triggered()),this,SLOT(changeDirectory())); //changeDirectory(); fillList(); } +void Picture::log(){ + QByteArray cmdoutput = commandProcess.readAllStandardOutput(); + QString txtoutput = cmdoutput; + ui->log->append(txtoutput); + cmdoutput = commandProcess.readAllStandardError(); + txtoutput = cmdoutput; + ui->log->append(txtoutput); +} + std::string exec(char* cmd) { FILE* pipe = popen(cmd, "r"); if (!pipe) return "ERROR"; @@ -37,13 +48,13 @@ void Picture::fillList() { ui->fileList->clear(); //ui->fileList->addItems(directory.entryList()); foreach(const QString &str,directory.entryList()){ - QImageReader reader(directory.absolutePath()+"/"+str); - if(!reader.format().isEmpty()){ - ui->fileList->addItem(str); - } + QImageReader reader(directory.absolutePath()+"/"+str); + if(!reader.format().isEmpty()){ + ui->fileList->addItem(str); + } } if(ui->fileList->count()==0){ - ui->fileList->addItem(""); + ui->fileList->addItem(""); } } void Picture::on_cd_clicked(){ @@ -60,7 +71,8 @@ void Picture::on_erase_clicked(){ char* a=new char[tmp2.size()+1]; a[tmp2.size()]=0; memcpy(a,tmp2.c_str(),tmp2.size()); - exec(a); + //exec(a); + commandProcess.start(a); }else{ if(!ignored){ ignored=true; @@ -73,10 +85,14 @@ void Picture::on_erase_clicked(){ } void Picture::on_refresh_clicked(){ fillList(); + ui->log->append("Refreshed directory"); } void Picture::on_clearLog_clicked(){ ui->log->setText(""); + ui->tabField->setCurrentIndex(0); } void Picture::on_erase_pressed(){ ui->log->append("Erasing metadata from images..."); + ui->tabField->setCurrentIndex(1); + on_erase_clicked(); } diff --git a/picture.h b/picture.h index 4a46ad5..ed733cf 100644 --- a/picture.h +++ b/picture.h @@ -13,6 +13,7 @@ #include #include #include +#include namespace Ui { class Picture; @@ -34,8 +35,10 @@ private slots: void on_refresh_clicked(); void on_clearLog_clicked(); void on_erase_pressed(); + void log(); private: Ui::Picture *ui; QDir directory; + QProcess commandProcess; }; #endif // PICTURE_H diff --git a/picture.ui b/picture.ui index 7997705..2d8eb55 100644 --- a/picture.ui +++ b/picture.ui @@ -14,77 +14,118 @@ Picture - + - 11 - 1 - 258 - 229 + 0 + 0 + 471 + 301 - - - - - - + + 0 + + + + Commands + + + + + 20 + 20 + 258 + 229 + + + - + + + + + + + + Change Directory + + + + + + + Refresh Directory + + + + + + + + + + + 300 + 60 + 107 + 62 + + + + + - Change Directory + Erase Metadata - + - Refresh Directory + Label - - - - - - - 310 - 10 - 124 - 27 - - - - Erase Metadata - - - - - - 310 - 60 - 301 - 191 - - - - true - - - - - - 561 - 222 - 51 - 30 - - - - Clear - + + fileList + fileList + layoutWidget + erase + pushButton + + + + Log + + + + + 10 + 10 + 381 + 192 + + + + true + + + + + + 270 + 220 + 51 + 30 + + + + Clear + + +