Attempting QProcess execution

This commit is contained in:
Austen Adler 2014-06-18 21:32:10 -04:00
parent e5a1b2283e
commit e1dbb7db6d
4 changed files with 123 additions and 63 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.0.1, 2014-06-18T14:39:43. --> <!-- Written by QtCreator 3.0.1, 2014-06-18T20:10:29. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>ProjectExplorer.Project.ActiveTarget</variable> <variable>ProjectExplorer.Project.ActiveTarget</variable>

View File

@ -3,10 +3,21 @@ Picture::Picture(QWidget *parent) :
QMainWindow(parent), QMainWindow(parent),
ui(new Ui::Picture){ ui(new Ui::Picture){
ui->setupUi(this); 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())); connect(ui->actionOpen_Files,SIGNAL(triggered()),this,SLOT(changeDirectory()));
//changeDirectory(); //changeDirectory();
fillList(); 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) { std::string exec(char* cmd) {
FILE* pipe = popen(cmd, "r"); FILE* pipe = popen(cmd, "r");
if (!pipe) return "ERROR"; if (!pipe) return "ERROR";
@ -37,13 +48,13 @@ void Picture::fillList() {
ui->fileList->clear(); ui->fileList->clear();
//ui->fileList->addItems(directory.entryList()); //ui->fileList->addItems(directory.entryList());
foreach(const QString &str,directory.entryList()){ foreach(const QString &str,directory.entryList()){
QImageReader reader(directory.absolutePath()+"/"+str); QImageReader reader(directory.absolutePath()+"/"+str);
if(!reader.format().isEmpty()){ if(!reader.format().isEmpty()){
ui->fileList->addItem(str); ui->fileList->addItem(str);
} }
} }
if(ui->fileList->count()==0){ if(ui->fileList->count()==0){
ui->fileList->addItem("<NO PICTURES>"); ui->fileList->addItem("<NO PICTURES>");
} }
} }
void Picture::on_cd_clicked(){ void Picture::on_cd_clicked(){
@ -60,7 +71,8 @@ void Picture::on_erase_clicked(){
char* a=new char[tmp2.size()+1]; char* a=new char[tmp2.size()+1];
a[tmp2.size()]=0; a[tmp2.size()]=0;
memcpy(a,tmp2.c_str(),tmp2.size()); memcpy(a,tmp2.c_str(),tmp2.size());
exec(a); //exec(a);
commandProcess.start(a);
}else{ }else{
if(!ignored){ if(!ignored){
ignored=true; ignored=true;
@ -73,10 +85,14 @@ void Picture::on_erase_clicked(){
} }
void Picture::on_refresh_clicked(){ void Picture::on_refresh_clicked(){
fillList(); fillList();
ui->log->append("Refreshed directory");
} }
void Picture::on_clearLog_clicked(){ void Picture::on_clearLog_clicked(){
ui->log->setText(""); ui->log->setText("");
ui->tabField->setCurrentIndex(0);
} }
void Picture::on_erase_pressed(){ void Picture::on_erase_pressed(){
ui->log->append("Erasing metadata from images..."); ui->log->append("Erasing metadata from images...");
ui->tabField->setCurrentIndex(1);
on_erase_clicked();
} }

View File

@ -13,6 +13,7 @@
#include <QDebug> #include <QDebug>
#include <QImageReader> #include <QImageReader>
#include <QDialog> #include <QDialog>
#include <QProcess>
namespace Ui { namespace Ui {
class Picture; class Picture;
@ -34,8 +35,10 @@ private slots:
void on_refresh_clicked(); void on_refresh_clicked();
void on_clearLog_clicked(); void on_clearLog_clicked();
void on_erase_pressed(); void on_erase_pressed();
void log();
private: private:
Ui::Picture *ui; Ui::Picture *ui;
QDir directory; QDir directory;
QProcess commandProcess;
}; };
#endif // PICTURE_H #endif // PICTURE_H

View File

@ -14,77 +14,118 @@
<string>Picture</string> <string>Picture</string>
</property> </property>
<widget class="QWidget" name="centralWidget"> <widget class="QWidget" name="centralWidget">
<widget class="QWidget" name="layoutWidget"> <widget class="QTabWidget" name="tabField">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>11</x> <x>0</x>
<y>1</y> <y>0</y>
<width>258</width> <width>471</width>
<height>229</height> <height>301</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <property name="currentIndex">
<item> <number>0</number>
<widget class="QListWidget" name="fileList"/> </property>
</item> <widget class="QWidget" name="tab">
<item> <attribute name="title">
<layout class="QHBoxLayout" name="horizontalLayout"> <string>Commands</string>
</attribute>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>20</x>
<y>20</y>
<width>258</width>
<height>229</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<widget class="QPushButton" name="cd"> <widget class="QListWidget" name="fileList"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="cd">
<property name="text">
<string>Change Directory</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="refresh">
<property name="text">
<string>Refresh Directory</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="">
<property name="geometry">
<rect>
<x>300</x>
<y>60</y>
<width>107</width>
<height>62</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QPushButton" name="erase">
<property name="text"> <property name="text">
<string>Change Directory</string> <string>Erase Metadata</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="refresh"> <widget class="QPushButton" name="pushButton">
<property name="text"> <property name="text">
<string>Refresh Directory</string> <string>Label</string>
</property> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</item> </widget>
</layout> <zorder>fileList</zorder>
</widget> <zorder>fileList</zorder>
<widget class="QPushButton" name="erase"> <zorder>layoutWidget</zorder>
<property name="geometry"> <zorder>erase</zorder>
<rect> <zorder>pushButton</zorder>
<x>310</x> </widget>
<y>10</y> <widget class="QWidget" name="tab_2">
<width>124</width> <attribute name="title">
<height>27</height> <string>Log</string>
</rect> </attribute>
</property> <widget class="QTextEdit" name="log">
<property name="text"> <property name="geometry">
<string>Erase Metadata</string> <rect>
</property> <x>10</x>
</widget> <y>10</y>
<widget class="QTextEdit" name="log"> <width>381</width>
<property name="geometry"> <height>192</height>
<rect> </rect>
<x>310</x> </property>
<y>60</y> <property name="readOnly">
<width>301</width> <bool>true</bool>
<height>191</height> </property>
</rect> </widget>
</property> <widget class="QPushButton" name="clearLog">
<property name="readOnly"> <property name="geometry">
<bool>true</bool> <rect>
</property> <x>270</x>
</widget> <y>220</y>
<widget class="QPushButton" name="clearLog"> <width>51</width>
<property name="geometry"> <height>30</height>
<rect> </rect>
<x>561</x> </property>
<y>222</y> <property name="text">
<width>51</width> <string>Clear</string>
<height>30</height> </property>
</rect> </widget>
</property> </widget>
<property name="text">
<string>Clear</string>
</property>
</widget> </widget>
</widget> </widget>
<widget class="QMenuBar" name="menuBar"> <widget class="QMenuBar" name="menuBar">