PDA

View Full Version : App dissapears from Task Manager when running a QProcess



INeedADollar
16th September 2019, 17:23
Hello! I have a problem. When I run a QProcess for the first time, my app is shown in Task Manager with all processes.
13261

When I run the same QProcess second time my app dissapears from Task Manager.
13262

When the QProcess is finished after started second time, app is shown again in Task Manager but without its process.
13263

My code:

mainwindow.h


#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QWidget>
class mainWindow : public QWidget
{
Q_OBJECT
public:
mainWindow(QWidget *parent = 0);
~mainWindow();
void createUI();
void process();
QProcess *process = new QProcess(this);

private slots:
void ReadOutput(int, QProcess::ExitStatus);

};
#endif // MAINWINDOW_H


mainwindow.cpp


#include <QWidget>
#include <QPushButton>
#include <QProcess>
#include <QByteArray>
#include <QTextCodec>
#include <QString>
#include <QDebug>
#include "mainwindow.h"

mainWindow::mainWindow(QWidget *parent) : QWidget(parent)
{
createUI();
connect(process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(ReadOutput(int, QProcess::ExitStatus)));
}


mainWindow::~mainWindow()
{

}
void mainWindow::createUI(){
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(){
process->setProcessChannelMode(QProcess::MergedChannels);
process->start("\"D:\\YTDownloader\\youtube-dl.exe\" -e --no-playlist https://www.youtube.com/watch?v=6V-wwfuxZxw");

void readOutput(int exitCode, QProcess::ExitStatus exitStatus){
qDebug() << exitCode;
qDebug() << exitStatus;
QByteArray a = process->readAllStandardOutput();
QTextCodec* utfCodec = QTextCodec::codecForName("UTF-8");
processStdout = utfCodec->toUnicode(a);
qDebug() << processStdout;
}


main.cpp


#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();
}


How can this be solved? Thank you!

d_stranz
17th September 2019, 03:23
It may not be the reason, but you are calling QProcess::start() incorrectly. The preferred way is to specify the first argument as a QString containing the name of the program to be executed (your youtube-dl.exe), and the second argument a QStringList where each item in the list is one of the individual command line arguments. In your case, this should be:



QString program = "D:\\YTDownloader\\youtube-dl.exe";
QStringList args;
args << "-e" << "--no-playlist" << "https://www.youtube.com/watch?v=6V-wwfuxZxw";
process->start( program, args );


Also, Task Manager has a default update rate. (View->Update speed) If your process starts and ends in less time than the update interval, it may not show up.

INeedADollar
18th September 2019, 17:30
It may not be the reason, but you are calling QProcess::start() incorrectly. The preferred way is to specify the first argument as a QString containing the name of the program to be executed (your youtube-dl.exe), and the second argument a QStringList where each item in the list is one of the individual command line arguments. In your case, this should be:



QString program = "D:\\YTDownloader\\youtube-dl.exe";
QStringList args;
args << "-e" << "--no-playlist" << "https://www.youtube.com/watch?v=6V-wwfuxZxw";
process->start( program, args );


Also, Task Manager has a default update rate. (View->Update speed) If your process starts and ends in less time than the update interval, it may not show up.

Thank you very much!