ok, I manage to remove threads and yes, QProcess is async, but..seems that tries to convert all at the same time, that's why I was using waitforfinish...my updated codes:
Qt Code:
  1. #ifndef TEST01_HPP
  2. #define TEST01_HPP
  3.  
  4. #include <QApplication>
  5. #include <QWidget>
  6. #include <QFileDialog>
  7. #include <QDir>
  8. #include <QDesktopServices> // Qt 4.2
  9. #include "ui_test01.h"
  10. #include "ffmpeg_runner.hpp"
  11.  
  12. namespace Ui {
  13. class Form;
  14. };
  15.  
  16. class MyForm : public QWidget {
  17. Q_OBJECT
  18. private:
  19. Ui::Form *ui;
  20. MyFfmpegRunnerClass *ffmpeg;
  21. public:
  22. MyForm(QWidget *root = 0) : QWidget(root), ui(new Ui::Form)
  23. {
  24. ui->setupUi(this);
  25.  
  26. /* below is beta, watch it!!! */
  27. ffmpeg = new MyFfmpegRunnerClass(this);
  28. connect(ffmpeg, SIGNAL(startJob()), this, SLOT(handleStart()));
  29. connect(ffmpeg, SIGNAL(endJob()), this, SLOT(handleEnd()));
  30. /* ... */
  31.  
  32. connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(handleRunButton()));
  33. connect(ui->pushButton_3, SIGNAL(clicked()), this, SLOT(handleBrowseButton()));
  34. ui->lineEdit->setText(QDesktopServices::storageLocation(QDesktopServices::MoviesLocation));
  35. }
  36. virtual ~MyForm() {
  37. delete ffmpeg;
  38. delete ui;
  39. }
  40.  
  41. protected:
  42.  
  43. signals:
  44. void doneJob();
  45.  
  46. protected slots:
  47. void handleBrowseButton() {
  48. QString folder = QFileDialog::getExistingDirectory(this);
  49. if (!folder.isEmpty()) ui->lineEdit->setText(folder);
  50. }
  51.  
  52. void handleRunButton() {
  53. QString source_dir = ui->lineEdit->text();
  54. QString target_dir = QDesktopServices::storageLocation(QDesktopServices::MusicLocation);
  55. bool delete_me = true;
  56. ffmpeg->Start(source_dir, target_dir, delete_me);
  57. }
  58.  
  59. void handleStart() {
  60. qDebug() << "We start the process";
  61. }
  62.  
  63. void handleEnd() {
  64. qDebug() << "Done :v";
  65. }
  66.  
  67. };
  68.  
  69. #endif
To copy to clipboard, switch view to plain text mode 
Qt Code:
  1. #ifndef FFMPEG_RUNNER_HPP
  2. #define FFMPEG_RUNNER_HPP
  3.  
  4. #include <QDebug>
  5. #include <QDir>
  6. #include <QFileInfo>
  7. #include <QProcess>
  8.  
  9. class MyFfmpegRunnerClass : public QObject {
  10. Q_OBJECT
  11. private:
  12. QProcess *process;
  13. QString curr_file;
  14. bool delete_me;
  15. int n_files;
  16. public:
  17. MyFfmpegRunnerClass(QObject *parent = 0) : QObject(parent)
  18. {
  19. n_files = 0;
  20. process = new QProcess(this);
  21. process->setStandardOutputFile("/dev/null");
  22. process->setStandardErrorFile("/dev/null");
  23. connect(process, SIGNAL(started()), this, SLOT(handleprocessStarted()));
  24. connect(process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(handleprocessExited(int, QProcess::ExitStatus)));
  25. }
  26.  
  27. void Start(const QString& srcdir, const QString& outdir, bool be_deleted = false) {
  28. QDir folder(srcdir);
  29. folder.setNameFilters(QStringList() << "*.mp3" << "*.mp4" << "*.flv" << "*.wav" << "*.ogg" << "*.3gp");
  30. QStringList files = folder.entryList(QDir::NoDotAndDotDot|QDir::Files);
  31. delete_me = be_deleted;
  32. n_files = files.size();
  33. int index;
  34. for (index = 0; index != n_files; index++) {
  35. QFileInfo fi(srcdir, files.at(index));
  36. QString file = fi.baseName() + ".mp3";
  37. curr_file = fi.absoluteFilePath();
  38. QString out_file = QDir(outdir).filePath(file);
  39. qDebug() << "Converting: " << curr_file;
  40. process->start("ffmpeg", QStringList() << "-i" << curr_file << "-f" << "mp3" << "-ab" << "128k" << out_file);
  41. }
  42. // here we should wait until all files are converted, right?
  43. qDebug() << "Why do you see this line even the process is still converting?"
  44. }
  45.  
  46. ~MyFfmpegRunnerClass() {
  47. if (process->pid()) process->close();
  48. delete process;
  49. qDebug() << "Class ffmpeg died";
  50. }
  51.  
  52. protected slots:
  53. void handleprocessStarted() {
  54. emit startJob();
  55. }
  56.  
  57. void handleprocessExited(int exitCode, QProcess::ExitStatus exitStatus) {
  58. qDebug() << "Exited code: " << exitCode << ". ExitStatus: " << exitStatus;
  59. if ( (exitCode == 0) && (delete_me) ) {
  60. process->close();
  61. emit endJob();
  62. // you should delete source file here
  63. }
  64. }
  65.  
  66. signals:
  67. void startJob();
  68. void endJob();
  69. };
  70.  
  71.  
  72. #endif
To copy to clipboard, switch view to plain text mode