Running a Unix command programmatically with QT

  • I am just learning unix and QT. I want to send a command out through qt to Unix. I've tried this code and I don't get the result i do when I do it in the terminal. What is going wrong here?

    @#ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>
    #include "QProcess"

    namespace Ui {
    class MainWindow;

    class MainWindow : public QMainWindow

    explicit MainWindow(QWidget *parent = 0);

    private slots:
    void on_pushButton_clicked();

    Ui::MainWindow *ui;
    QProcess *m_process;

    #endif // MAINWINDOW_H@

    @#include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include "QDebug"

    MainWindow::MainWindow(QWidget *parent) :
    ui(new Ui::MainWindow)
    m_process = new QProcess(this);

    delete ui;

    void MainWindow::on_pushButton_clicked()
    QString cmd = "printf "testnc" | nc localhost 1235";
    qDebug() << cmd;

    qDebug() << "Got here.";


  • When I click the go button, the code executes but my "listener" at the other end isn't getting the message.

    If I run the command:

    printf "testnc" | nc localhost 1235

    from the terminal, my listener picks it up fine.

  • Moderators

    Piping does not work in QProcess.

    You can simulate it be redirecting output from one QProcess to the other. Or use my "QEasyShell": project, it might just work ;P.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.