Results 1 to 9 of 9

Thread: Re: Quick help on QProcess

  1. #1
    Join Date
    Jul 2007
    Posts
    27
    Thanks
    4
    Thanked 1 Time in 1 Post

    Red face Re: Quick help on QProcess

    I think is valid:
    Qt Code:
    1. out->append(process.readAllStandardOutput());
    To copy to clipboard, switch view to plain text mode 

    I'm try create simple application when using QProcess class,
    but I didn't receive output buffer.

    Qt Code:
    1. //main.cpp
    2. #include <QApplication>
    3. #include "dialogimpl.h"
    4. //
    5. int main(int argc, char ** argv)
    6. {
    7. QApplication app( argc, argv );
    8. DialogImpl win;
    9. win.show();
    10. app.connect( &app, SIGNAL( lastWindowClosed() ), &app, SLOT( quit() ) );
    11. return app.exec();
    12. }
    13.  
    14. ///////////////////////////////////////////////////////////////////////////////////////////////////////
    15. // dialogimpl.cpp
    16. #include "dialogimpl.h"
    17. #include <QProcess>
    18. //
    19. DialogImpl::DialogImpl( QWidget * parent, Qt::WFlags f)
    20. : QDialog(parent, f)
    21. {
    22. setupUi(this);
    23. process = new QProcess(this);
    24. process->setReadChannel(QProcess::StandardOutput);
    25. connect(process, SIGNAL(readyReadStandardOutput()), this, SLOT(output()));
    26. connect(pushButton, SIGNAL(clicked()), this, SLOT(runcmd()));
    27. }
    28. //
    29. void DialogImpl::output()
    30. {
    31. textEdit->append((process->readAllStandardOutput()));
    32. }
    33. //
    34. void DialogImpl::runcmd()
    35. {
    36. process->start(lineEdit->text());
    37. }
    38.  
    39. ///////////////////////////////////////////////////////////////////////////////////////////////////////
    40. // dialogimpl.h
    41. #ifndef DIALOGIMPL_H
    42. #define DIALOGIMPL_H
    43. //
    44. #include "ui_dialog.h"
    45. //
    46. class QProcess;
    47.  
    48. class DialogImpl : public QDialog, public Ui::Dialog
    49. {
    50. Q_OBJECT
    51. public:
    52. DialogImpl( QWidget * parent = 0, Qt::WFlags f = 0 );
    53. private slots:
    54. void output();
    55. void runcmd();
    56. private:
    57. QProcess* process;
    58. };
    59. #endif
    To copy to clipboard, switch view to plain text mode 

    Where I was mistaken?
    Excuse me for English, I from Russia

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Quick help on QProcess

    What happens if you add:
    Qt Code:
    1. connect( process, SIGNAL(started()), QCoreApplication::instance(), SLOT(aboutQt()) );
    To copy to clipboard, switch view to plain text mode 
    at the end of dialog's constructor?

  3. #3
    Join Date
    Jul 2007
    Posts
    27
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Re: Quick help on QProcess

    Strange situation,
    if I run "calc.exe" (for example), it's working (calculator running) and About dialog was shown.
    If I run "dir", it's not working, and About dialog was not shown.

    Excuse me for English, I from Russia

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Quick help on QProcess

    But dir is not a real application. It is just built in command prompt.
    On the other hand, calc is an application and can be a process.

    If you want to use command scripting, then use batch files. Execute them like this:
    "cmd.exe my_batchFile.bat"

    Regards

  5. The following user says thank you to marcel for this useful post:

    ufo-vl (27th July 2007)

  6. #5
    Join Date
    Jul 2007
    Posts
    27
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Re: Quick help on QProcess

    It is very a shame to me. I have absolutely forgotten it.:-(.
    Many thanks
    Excuse me for English, I from Russia

  7. #6
    Join Date
    Jul 2007
    Posts
    27
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Re: Quick help on QProcess

    And one question,
    when started program,
    CONSOLE dialog was shown. Can I to get rid of it?
    I'm planned run console commands and taking output from console,
    but I do not need to be shown the console thus.
    Excuse me for English, I from Russia

  8. #7
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Quick help on QProcess

    No, I don't think you can do that.
    You cannot run cmd without the window.

    Regards

  9. #8
    Join Date
    Jul 2007
    Posts
    27
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Re: Quick help on QProcess

    It is a pity.
    But the problem not only at use CMD, at start of the program (which uses QProcess) console dialog was shown :-(.
    Excuse me for English, I from Russia

  10. #9
    Join Date
    Jul 2007
    Posts
    27
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Re: Quick help on QProcess

    The question is solved.
    A problem in absence of a patch for hands )
    Excuse me for English, I from Russia

Similar Threads

  1. Quick help on QProcess
    By devilj in forum Newbie
    Replies: 4
    Last Post: 17th July 2007, 22:16
  2. QProcess and Pipes
    By KaptainKarl in forum Qt Programming
    Replies: 1
    Last Post: 9th April 2007, 23:11
  3. QProcess extremely slow on Windows?
    By Pepe in forum Qt Programming
    Replies: 2
    Last Post: 26th March 2007, 00:25
  4. problem with qprocess
    By deekayt in forum Qt Programming
    Replies: 2
    Last Post: 13th June 2006, 13:30
  5. QProcess in a QThread
    By chombium in forum Qt Programming
    Replies: 2
    Last Post: 11th January 2006, 15:52

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.