Results 1 to 6 of 6

Thread: Shell command from Qt 4.5.2 by QProcess

  1. #1
    Join Date
    Sep 2009
    Posts
    39
    Thanks
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Arrow Shell command from Qt 4.5.2 by QProcess

    Hi Everyone.........
    Plz can you send me small code just it has to send some command to CLI. I'm working in ARM i.MX31 ARM board. I need to interact CLI by using Qt 4.5.2. So i need just a simple code to execute on CLI (command Line Interface). For example i need to see all list of folders or dir on Root file system(rfs). Plz can you check it out, give solution how to do it. If i click on button it has to display list of folders and dir on CLI first.
    Im writing my complete code of my project here and im attaching .ui file as in zip format. Plz check it out, assit me to pass commands for CLI. plz quote an small example also.overall if i click on button on GUI. it has to send command "ls -l" to CLI, Atleast i need to list of folders and directories on CLI after cancelling GUI, later on i can work it out to bring uo data on CLI to textedit box.. Thanking you in advance see all my attached and written code below.

    Asking directly my AIM is to just click on button, if i cancel GUI. atleast i want see "ls -l" cmd on terminal and it should have list all the folders and directories.


    QPROCESS.PRO
    ================================================== ============================================
    #-------------------------------------------------
    #
    # Project created by QtCreator 2009-12-10T15:21:05
    #
    #-------------------------------------------------

    TARGET = Qprocess
    TEMPLATE = app


    SOURCES += main.cpp\
    mainwindow.cpp

    HEADERS += mainwindow.h

    FORMS += mainwindow.ui
    ================================================== ================================================== ==========

    main.cpp
    ================================================== ================================================== ==========
    #include <QtGui/QApplication>
    #include "mainwindow.h"

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    MainWindow w;
    w.show();
    return a.exec();
    }
    ================================================== ================================================== ===========
    mainwindow.cpp
    ================================================== ================================================== ===========
    #include "mainwindow.h"
    #include "ui_mainwindow.h"

    MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent), ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    pushbutton =new QPushButton;
    pushbutton=ui->pushButton;

    connect(pushbutton,SIGNAL(clicked()),this,SLOT(but tonclicked()));





    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }

    void MainWindow::buttonclicked()
    {
    pushbutton->setText("VINAY");
    proc=new QProcess(this);
    proc->start("VKB -qws");//Actually i want to give commands like ls -l or cd .. which should be passed to CLI and act on that. but im not finding options in proc-> . Plz can you send me a small code to interact with CLI.

    }
    ================================================== ================================================== ===========
    mainwindow.h
    ================================================== ================================================== ===========
    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QtGui/QMainWindow>
    #include <QProcess>
    #include <QPushButton>
    #include <QTextEdit>
    class QProcess;

    namespace Ui
    {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    MainWindow(QWidget *parent = 0);
    ~MainWindow();

    private:
    Ui::MainWindow *ui;
    private:
    QProcess *proc;
    QPushButton *pushbutton;
    private slots:
    void buttonclicked();
    };

    #endif // MAINWINDOW_H
    ================================================== ===================================
    Attached Files Attached Files

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Shell command from Qt 4.5.2 by QProcess

    Quote Originally Posted by Rajeshsan View Post
    Hi Everyone.........
    Plz can you send me small code just it has to send some command to CLI.
    [...]
    proc=new QProcess(this);
    proc->start("VKB -qws");//Actually i want to give commands like ls -l or cd .. which should be passed to CLI and act on that. but im not finding options in proc-> . Plz can you send me a small code to interact with CLI.
    Before begging for code, I would recommend using the CODE tags and read the docs regarding QProcess and learn how the right syntax would look like.

  3. #3
    Join Date
    Sep 2009
    Posts
    39
    Thanks
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Shell command from Qt 4.5.2 by QProcess

    Hi.... I have sent full code. So plz can you see the code then you can suggest me. how to pass arguments for Shell from Qt. I need to develop just a LineEdit. In LineEdit what i type like command "ls -l". It should appear on CLI then it should display the list of Folders and directories. I need just simple application like this or plz send simple code to do it.

  4. #4
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Shell command from Qt 4.5.2 by QProcess

    Quote Originally Posted by Rajeshsan View Post
    i need to see all list of folders or dir on Root file system(rfs).
    Use QDir in this case.

    If you wish to send other commands, then refer to QProcess documentation. Note that arguments must be seperate from the command to be executed (look at QStringList).

  5. #5
    Join Date
    Sep 2009
    Posts
    39
    Thanks
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Arrow Re: Shell command from Qt 4.5.2 by QProcess

    Sorry.. Actually I wanted to implement on my board fast. so im searching fastly. I thot of replying you but now im getting partial outputs. So I'm eager to do fast. Now im able to get cmd.exe(wiindows) or terminal.exe(linux).just proc->start("cmd.exe/terminal.exe"). I need to send command to same terminal or command prompt directly from same program or window. I studied full documentation but i didmt suceed in sending commands to it. So I dont no how exactly it happens. I have sent code. QDir i implented as you suggested but it didnt work. Sorry.

  6. #6
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Shell command from Qt 4.5.2 by QProcess

    Why not run each command seperately? It would be much easier. For example, 'dir' command can be run like:
    Qt Code:
    1. p.start("cmd.exe", QStringList() << "/c" << "dir");
    2. if (p.waitForStarted())
    3. {
    4. p.waitForFinished();
    5. qDebug() << p.readAllStandardOutput();
    6. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QProcess & linux shell characters
    By Ti_Thom in forum Qt Programming
    Replies: 4
    Last Post: 21st December 2009, 10:01
  2. qprocess and shell
    By GuL in forum Qt Programming
    Replies: 1
    Last Post: 12th February 2009, 05:47
  3. Detect First QProcess finished in a group and kill other
    By Davidaino in forum Qt Programming
    Replies: 3
    Last Post: 11th July 2008, 12:53

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.