You are not logged in.

Dear visitor, welcome to If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.


Friday, May 26th 2017, 4:58am

how to write runtime input to external jar from qt creator console

I am developing qt widgets application to run external jar file and display the jar output on qt gui touch diaplay.
In such a way my external jar file,executed while user given runtime input then process and print the output.(Both read and write)
Here, i executed jar file using QProcess. Process (jar execution) started running, waiting for user input. I cannot give runtime input to my external jar file through both qt console and terminal window. please suggest how to write input and read output back from external jar file through qt.

This is our jar (sample.jar) contained java application file (.java). Export this .java file as executable sample.jar file.

import java.util.Scanner;

public class RuntimeInput {

public static void main(String args[]){
System.out.println("Reading jar file");

System.out.println("Enter Consumer No: ");

Scanner inputReader = new Scanner(;

String name = inputReader.nextLine();
System.out.println("Hi " + name);

Expected Qt output:

Run executable jar in cmd window getting like this,

D:\>java -jar sample.jar

Reading jar file
Enter Consumer No:
Hi 124569896


#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QTextStream>
#include <QByteArray>
#include <QProcess>
#include <QDebug>

MainWindow::MainWindow(QWidget *parent) :
ui(new Ui::MainWindow)

delete ui;

void MainWindow::on_pushButton_clicked()

cmd = new QProcess(this);

connect( cmd, SIGNAL(readyReadStandardError()), this, SLOT(handleReadStandardError()) );

connect( cmd, SIGNAL(readyReadStandardOutput()), this, SLOT(handleReadStandardOutput()) );

QStringList arguments;
arguments << "-jar" << "D:\\sample.jar";

cmd->start("java", arguments, QIODevice::ReadWrite);

//cmd->execute("java -jar D:\\sample.jar");

if ( cmd->state() == QProcess::NotRunning ) {
qDebug() << "The process is not running.It exits";
else if ( cmd->state() == QProcess::Starting ) {
qDebug() << "The process is started, but the program has not yet been invoked.";
}else if ( cmd->state() == QProcess::Running ) {
qDebug() << "The process is running and is ready for reading and writing.";

if (!cmd->waitForStarted()) {
qDebug() << "Not yet started";



void MainWindow::handleReadStandardError()
QByteArray data = cmd->readAllStandardError();
qDebug() << data;

void MainWindow::handleReadStandardOutput()
QByteArray data = cmd->readAllStandardOutput();
qDebug() << "Data:\n" << data << endl;


QT Console output:

Starting D:\ANNIE\QT Workspace\build-Samplewrite-Desktop_Qt_5_7_1_MinGW_32bit-Debug\debug\Samplewrite.exe...
The process is running and is ready for reading and writing.

"Reading jar file \r\n
Enter Consumer No: \r\n"