Results 1 to 18 of 18

Thread: ReadAllStandardOutput() is returning empty characters if they are not recognised

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: ReadAllStandardOutput() is returning empty characters if they are not recognised

    I get the same result.
    Then maybe your "youtube-dl" program itself does not support Unicode.
    <=== 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.

  2. #2
    Join Date
    Jul 2019
    Posts
    32
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: ReadAllStandardOutput() is returning empty characters if they are not recognised

    Quote Originally Posted by d_stranz View Post
    Then maybe your "youtube-dl" program itself does not support Unicode.
    Hmmm, curious because when I run the command in cmd I get the correct title with all characters.

  3. #3
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: ReadAllStandardOutput() is returning empty characters if they are not recognised

    Can you please show us your code?

  4. #4
    Join Date
    Jul 2019
    Posts
    32
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: ReadAllStandardOutput() is returning empty characters if they are not recognised

    Quote Originally Posted by ChristianEhrlicher View Post
    Can you please show us your code?
    Yes, of course.

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

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

  5. #5
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: ReadAllStandardOutput() is returning empty characters if they are not recognised

    Perhaps the problem is the Windows code page. I did the test with "Polish letters" and everything is OK but the result from youtube-dl is encoded in 1250 (8-bit code page) and not UTF-8. This is the link used for the test: https://www.youtube.com/watch?v=ndG8bM-9CMA
    Can you provide the Japanese alphabet link to test?
    P.S.
    Test with arabic alphabet : https://www.youtube.com/watch?v=7Tc7LWpe7mg. Output generated on Windows is 29 bytes long, on Linux 85 bytes long. In my opinion it's an internal problem of youtube-dl.
    Last edited by Lesiok; 19th August 2019 at 12:08.

  6. #6
    Join Date
    Jul 2019
    Posts
    32
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: ReadAllStandardOutput() is returning empty characters if they are not recognised

    Quote Originally Posted by Lesiok View Post
    Perhaps the problem is the Windows code page. I did the test with "Polish letters" and everything is OK but the result from youtube-dl is encoded in 1250 (8-bit code page) and not UTF-8. This is the link used for the test: https://www.youtube.com/watch?v=ndG8bM-9CMA
    Can you provide the Japanese alphabet link to test?
    P.S.
    Test with arabic alphabet : https://www.youtube.com/watch?v=7Tc7LWpe7mg. Output generated on Windows is 29 bytes long, on Linux 85 bytes long. In my opinion it's an internal problem of youtube-dl.
    Link with Japanese Alphabet: https://www.youtube.com/watch?v=Bsfi4XbPE8M. I tried your link both with cmd and then with QProcess. When I tried the command in cmd with arabic alphabet link I got something like this ????? ??????? ?????? _35_ ????? ?????? The Ultimate Ninj, but if I copy paste the output(the title) in a browser I get the correct title.

    When I tried with QProcess I got something like this: " _35_ The Ultimate Ninj". Maybe it's a problem with youtube-dl, I don't know.

    I attached a photo to see how title looks after I copy-paste it in a browser from cmd.
    Attached Images Attached Images
    Last edited by INeedADollar; 19th August 2019 at 12:40.

  7. #7
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: ReadAllStandardOutput() is returning empty characters if they are not recognised

    definitely an environmental problem (operating system). On linux in a graphical environment (fonts installed for all alphabets) this result:
    gc.PNG
    On linux in a character environment like this:
    tc.jpg

  8. #8
    Join Date
    Jul 2019
    Posts
    32
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: ReadAllStandardOutput() is returning empty characters if they are not recognised

    Quote Originally Posted by Lesiok View Post
    definitely an environmental problem (operating system). On linux in a graphical environment (fonts installed for all alphabets) this result:
    gc.PNG
    On linux in a character environment like this:
    tc.jpg
    Ok thank you very much! Thank you very much all that tried to help me!

  9. #9
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: ReadAllStandardOutput() is returning empty characters if they are not recognised

    You're still outputting the data to the command line instead using a QMessageBox as I said in my second post so it can't work... https://www.qtcentre.org/threads/704...088#post306088

  10. #10
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: ReadAllStandardOutput() is returning empty characters if they are not recognised

    If it is a problem with the normal output of the Windows version of youtube-dl you could try its JSON output options.

    Cheers,
    _

Similar Threads

  1. Replies: 10
    Last Post: 6th February 2015, 12:41
  2. Replies: 13
    Last Post: 27th August 2014, 11:06
  3. QProcess::readAllStandardOutput and QTextEdit
    By naptizaN in forum Qt Programming
    Replies: 1
    Last Post: 13th December 2012, 07:50
  4. Returning const &
    By frenk_castle in forum Newbie
    Replies: 2
    Last Post: 24th November 2009, 07:01
  5. remove directory empty or not empty
    By raphaelf in forum Newbie
    Replies: 12
    Last Post: 27th October 2006, 07:30

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.