PDA

View Full Version : QProcess, how to correctly declare the variable, multiple event handlers.



TeODH4
11th June 2013, 09:29
Hey guys I know I'm doing something wrong here, any help would be much appreciated. I am trying to run mplayer in slave mode and control it. However I am having issues even controlling my QProcess! LOL I know I probably have to declare this process somewhere else before i start it, but I'm at a bit of a loss. It has been a long time since I have played around with QT. What do I need to be able to launch mplayer with a button, and close with another? Thanks.

mainwindow.cpp


#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QProcess>

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);


}

MainWindow::~MainWindow()
{
delete ui;


}

void MainWindow::on_pushButton_clicked()
{
QProcess* proc = new QProcess(this);
proc->setReadChannel(QProcess::StandardOutput);
proc->start("mplayer/mplayer.exe -vo direct3d -noborder -x 800 -y 600 -geometry 1025:0 -udp-master -udp-ip 192.168.2.255 -osdlevel 0 center.mp4");
}

void MainWindow::on_pushButton_2_clicked()
{
proc->terminate();
}


mainwindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QProcess>
namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
Q_OBJECT

public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();


private slots:
void on_pushButton_clicked();

void on_pushButton_2_clicked();

private:
Ui::MainWindow *ui;
QProcess *proc;

};

#endif // MAINWINDOW_H


Thanks in advanced,

Wayne

Added after 5 minutes:

Nevermind problem solved :-p I feel stupid now... Here's the solution... maybe it'll help someone else...



#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QProcess>

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
proc = new QProcess(this);

ui->setupUi(this);


}

MainWindow::~MainWindow()
{
delete ui;


}

void MainWindow::on_pushButton_clicked()
{
proc->setReadChannel(QProcess::StandardOutput);
proc->start("mplayer/mplayer.exe -vo direct3d -noborder -x 800 -y 600 -geometry 1025:0 -udp-master -udp-ip 192.168.2.255 -osdlevel 0 center.mp4");
}

void MainWindow::on_pushButton_2_clicked()
{
proc->terminate();
}