Originally Posted by
ChristianEhrlicher
Can you please show us your code?
Yes, of course.
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QWidget>
#include <QProcess>
#include <QString>
#include <QLabel>
{
Q_OBJECT
public:
mainWindow
(QWidget *parent
= nullptr
);
~mainWindow();
void createUI();
void process();
private slots:
void ReadOutput
(int,
QProcess::ExitStatus);
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QWidget>
#include <QProcess>
#include <QString>
#include <QLabel>
class mainWindow : public QWidget
{
Q_OBJECT
public:
mainWindow(QWidget *parent = nullptr);
~mainWindow();
void createUI();
void process();
QProcess *process1 = new QProcess(this);
QString processStdout;
QLabel *label;
private slots:
void ReadOutput(int, QProcess::ExitStatus);
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
mainwindow.cpp
#include "mainwindow.h"
#include <QPushButton>
#include <QtDebug>
#include <QTextCodec>
{
createUI();
connect(process1,
SIGNAL(finished
(int,
QProcess::ExitStatus)),
this,
SLOT(ReadOutput
(int,
QProcess::ExitStatus)));
}
mainWindow::~mainWindow()
{
}
void mainWindow::createUI(){
label->setGeometry(100, 200, 100, 30);
buttonsearch->setToolTip("Start process");
buttonsearch->setGeometry(200, 290, 100, 30);
connect(buttonsearch, &QPushButton::clicked, [this]() {process(); });
}
void mainWindow::process(){
process1
->setProcessChannelMode
(QProcess::MergedChannels);
process1->start("\"D:\\YTDownloader\\youtube-dl.exe\" -e --no-playlist https://www.youtube.com/watch?v=6V-wwfuxZxw");
}
void mainWindow
::ReadOutput(int exitCode,
QProcess::ExitStatus exitStatus
){ qDebug() << exitCode;
qDebug() << exitStatus;
qDebug() << a;
processStdout = utfCodec->toUnicode(a);
qDebug() << processStdout;
label->setText(processStdout);
}
#include "mainwindow.h"
#include <QPushButton>
#include <QtDebug>
#include <QTextCodec>
mainWindow::mainWindow(QWidget *parent) : QWidget(parent)
{
createUI();
connect(process1, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(ReadOutput(int, QProcess::ExitStatus)));
}
mainWindow::~mainWindow()
{
}
void mainWindow::createUI(){
label = new QLabel(this);
label->setGeometry(100, 200, 100, 30);
QPushButton *buttonsearch = new QPushButton("Start process", this);
buttonsearch->setToolTip("Start process");
buttonsearch->setGeometry(200, 290, 100, 30);
connect(buttonsearch, &QPushButton::clicked, [this]() {process(); });
}
void mainWindow::process(){
process1->setProcessChannelMode(QProcess::MergedChannels);
process1->start("\"D:\\YTDownloader\\youtube-dl.exe\" -e --no-playlist https://www.youtube.com/watch?v=6V-wwfuxZxw");
}
void mainWindow::ReadOutput(int exitCode, QProcess::ExitStatus exitStatus){
qDebug() << exitCode;
qDebug() << exitStatus;
QByteArray a = process1->readAllStandardOutput();
qDebug() << a;
QTextCodec* utfCodec = QTextCodec::codecForName("UTF-8");
processStdout = utfCodec->toUnicode(a);
qDebug() << processStdout;
label->setText(processStdout);
}
To copy to clipboard, switch view to plain text mode
main.cpp
#include <QApplication>
#include "mainwindow.h"
int main(int argl,char *argv[])
{
mainWindow *window = new mainWindow();
window->setWindowTitle("Test");
window->setFixedSize(700, 335);
window->show();
return app.exec();
}
#include <QApplication>
#include "mainwindow.h"
int main(int argl,char *argv[])
{
QApplication app(argl,argv);
mainWindow *window = new mainWindow();
window->setWindowTitle("Test");
window->setFixedSize(700, 335);
window->show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks