Results 1 to 3 of 3

Thread: App dissapears from Task Manager when running a QProcess

  1. #1
    Join Date
    Jul 2019
    Posts
    27
    Thanks
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default App dissapears from Task Manager when running a QProcess

    Hello! I have a problem. When I run a QProcess for the first time, my app is shown in Task Manager with all processes.
    Task Manager 1.png

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

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

    My code:

    mainwindow.h
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QWidget>
    5. class mainWindow : public QWidget
    6. {
    7. Q_OBJECT
    8. public:
    9. mainWindow(QWidget *parent = 0);
    10. ~mainWindow();
    11. void createUI();
    12. void process();
    13. QProcess *process = new QProcess(this);
    14.  
    15. private slots:
    16. void ReadOutput(int, QProcess::ExitStatus);
    17.  
    18. };
    19. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    mainwindow.cpp
    Qt Code:
    1. #include <QWidget>
    2. #include <QPushButton>
    3. #include <QProcess>
    4. #include <QByteArray>
    5. #include <QTextCodec>
    6. #include <QString>
    7. #include <QDebug>
    8. #include "mainwindow.h"
    9.  
    10. mainWindow::mainWindow(QWidget *parent) : QWidget(parent)
    11. {
    12. createUI();
    13. connect(process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(ReadOutput(int, QProcess::ExitStatus)));
    14. }
    15.  
    16.  
    17. mainWindow::~mainWindow()
    18. {
    19.  
    20. }
    21. void mainWindow::createUI(){
    22. QPushButton buttonsearch = new QPushButton("Start process", this);
    23. buttonsearch->setToolTip("Start process");
    24. buttonsearch->setGeometry(200, 290, 100, 30);
    25. connect(buttonsearch, &QPushButton::clicked, [this]() {process(); });
    26. }
    27.  
    28. void mainWindow::process(){
    29. process->setProcessChannelMode(QProcess::MergedChannels);
    30. process->start("\"D:\\YTDownloader\\youtube-dl.exe\" -e --no-playlist https://www.youtube.com/watch?v=6V-wwfuxZxw");
    31.  
    32. void readOutput(int exitCode, QProcess::ExitStatus exitStatus){
    33. qDebug() << exitCode;
    34. qDebug() << exitStatus;
    35. QByteArray a = process->readAllStandardOutput();
    36. QTextCodec* utfCodec = QTextCodec::codecForName("UTF-8");
    37. processStdout = utfCodec->toUnicode(a);
    38. qDebug() << processStdout;
    39. }
    To copy to clipboard, switch view to plain text mode 

    main.cpp
    Qt Code:
    1. #include <QApplication>
    2. #include "mainwindow.h"
    3.  
    4. int main(int argl,char *argv[])
    5. {
    6. QApplication app(argl,argv);
    7.  
    8. mainWindow *window = new mainWindow();
    9. window->setWindowTitle("Test");
    10. window->setFixedSize(700, 335);
    11. window->show();
    12.  
    13. return app.exec();
    14. }
    To copy to clipboard, switch view to plain text mode 

    How can this be solved? Thank you!

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,136
    Thanks
    235
    Thanked 660 Times in 650 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: App dissapears from Task Manager when running a QProcess

    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:

    Qt Code:
    1. QString program = "D:\\YTDownloader\\youtube-dl.exe";
    2. args << "-e" << "--no-playlist" << "https://www.youtube.com/watch?v=6V-wwfuxZxw";
    3. process->start( program, args );
    To copy to clipboard, switch view to plain text mode 

    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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Jul 2019
    Posts
    27
    Thanks
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: App dissapears from Task Manager when running a QProcess

    Quote Originally Posted by d_stranz View Post
    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:

    Qt Code:
    1. QString program = "D:\\YTDownloader\\youtube-dl.exe";
    2. args << "-e" << "--no-playlist" << "https://www.youtube.com/watch?v=6V-wwfuxZxw";
    3. process->start( program, args );
    To copy to clipboard, switch view to plain text mode 

    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!

Similar Threads

  1. QProcess is already running
    By Pvr in forum Qt Programming
    Replies: 1
    Last Post: 9th November 2018, 23:01
  2. Replies: 12
    Last Post: 18th September 2014, 19:54
  3. Hiding any running Application icon on windows task bar
    By nagabathula in forum Qt Programming
    Replies: 1
    Last Post: 22nd February 2012, 07:11
  4. Running an script using QProcess
    By DiegoTc in forum Newbie
    Replies: 1
    Last Post: 31st December 2010, 18:02
  5. Replies: 0
    Last Post: 26th August 2010, 10:44

Tags for this Thread

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.