Results 1 to 1 of 1

Thread: QProcess, how to correctly declare the variable, multiple event handlers.

  1. #1
    Join Date
    Jun 2013
    Posts
    1
    Qt products
    Qt5

    Default Re: QProcess, how to correctly declare the variable, multiple event handlers.

    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
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include <QProcess>
    4.  
    5. MainWindow::MainWindow(QWidget *parent) :
    6. QMainWindow(parent),
    7. ui(new Ui::MainWindow)
    8. {
    9. ui->setupUi(this);
    10.  
    11.  
    12. }
    13.  
    14. MainWindow::~MainWindow()
    15. {
    16. delete ui;
    17.  
    18.  
    19. }
    20.  
    21. void MainWindow::on_pushButton_clicked()
    22. {
    23. QProcess* proc = new QProcess(this);
    24. proc->setReadChannel(QProcess::StandardOutput);
    25. 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");
    26. }
    27.  
    28. void MainWindow::on_pushButton_2_clicked()
    29. {
    30. proc->terminate();
    31. }
    To copy to clipboard, switch view to plain text mode 

    mainwindow.h
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5. #include <QProcess>
    6. namespace Ui {
    7. class MainWindow;
    8. }
    9.  
    10. class MainWindow : public QMainWindow
    11. {
    12. Q_OBJECT
    13.  
    14. public:
    15. explicit MainWindow(QWidget *parent = 0);
    16. ~MainWindow();
    17.  
    18.  
    19. private slots:
    20. void on_pushButton_clicked();
    21.  
    22. void on_pushButton_2_clicked();
    23.  
    24. private:
    25. Ui::MainWindow *ui;
    26. QProcess *proc;
    27.  
    28. };
    29.  
    30. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    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...

    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include <QProcess>
    4.  
    5. MainWindow::MainWindow(QWidget *parent) :
    6. QMainWindow(parent),
    7. ui(new Ui::MainWindow)
    8. {
    9. proc = new QProcess(this);
    10.  
    11. ui->setupUi(this);
    12.  
    13.  
    14. }
    15.  
    16. MainWindow::~MainWindow()
    17. {
    18. delete ui;
    19.  
    20.  
    21. }
    22.  
    23. void MainWindow::on_pushButton_clicked()
    24. {
    25. proc->setReadChannel(QProcess::StandardOutput);
    26. 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");
    27. }
    28.  
    29. void MainWindow::on_pushButton_2_clicked()
    30. {
    31. proc->terminate();
    32. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by TeODH4; 11th June 2013 at 08:29.

Similar Threads

  1. How to declare global variable outside a class?
    By babygal in forum Qt Programming
    Replies: 2
    Last Post: 26th August 2010, 08:35
  2. how to declare a global variable right
    By Cruz in forum Newbie
    Replies: 13
    Last Post: 16th February 2010, 16:25
  3. Replies: 2
    Last Post: 17th December 2009, 14:01
  4. QProcess Bash in Event Filter (Multiple Processes)
    By Arsenic in forum Qt Programming
    Replies: 1
    Last Post: 8th November 2008, 08:42
  5. how to declare a friend variable ?
    By probine in forum General Programming
    Replies: 5
    Last Post: 27th March 2006, 15:00

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.