You are not logged in.

1

Wednesday, May 5th 2010, 7:54am

Running External c++ program when user hit ok button

hello ...
I want to create a gui which runs a c++ program
i have a code here ...

QProcess proc;
proc.start("proc.exe");
proc.waitForStarted();
proc.write("3\n"); // input from a radio button as i have switch case in my c++ program
proc.write("7\n"); // input from a radio button as i have need integer between 1-9 as cut off
proc.write("file\n"); //file upload for reading by program ....
proc.waitForFinished();

but i want the proc.write to be user defined from my gui ....



my program needs these 3 inputs from command line ...
please help ..

thanks in advance ....

This post by "xuebao" (Tuesday, June 15th 2010, 2:56am) has been deleted by user "Junior" (Thursday, June 17th 2010, 6:24pm) with the following reason: spammer

3

Tuesday, June 15th 2010, 9:51am

Make a new line edit. there user can give input.Let's say it's called Line_edit_5 And now we have

Source code

1
2
3
char buff1[30]=" "; //empty char
strcat(buff1,ui->Line_edit_5->text().toAscii()); //now buff1 is what Line_edit_5 contains
proc.write(buff1);


And if you wnat on button click, then create a new button (then right click, go to slot clicked()) and add the code I gave you above....

This post has been edited 1 times, last edit by "alex9090" (Jun 15th 2010, 11:57am)


This post by "xuebao" (Tuesday, June 29th 2010, 2:25am) has been deleted by user "Junior" (Wednesday, July 7th 2010, 2:26pm) with the following reason: spammer

5

Friday, July 2nd 2010, 1:04pm

thanks alex I got it working illl put the codes below hope some 1 will get benefited by the code

process.cpp


Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include  #include "promo.h" 
 promotif::promotif(QWidget *parent)
{  
setupUi(this);
connect( pushButton_browse, SIGNAL( clicked() ), this, SLOT( getPath() ) );
 connect( pushButton_run, SIGNAL( clicked() ), this, SLOT( run() ) ); 
}
 QString path; 
QProcess promo;
void promotif::getPath()
{

    path = QFileDialog::getOpenFileName(        this,        "Choose a file to open",        QString::null,        QString::null); lineEdit->setText( path );
}
void promotif::run(){

            QString str;  QString combo;


 promo.start("a.exe")
promo.waitForStarted();

if(radioButton->isChecked())
 promo.write("1\n");
if(radioButton_2->isChecked()) 
 promo.write("2\n");
if(radioButton_3->isChecked())
 promo.write("3\n");
if(radioButton_4->isChecked()) 
 promo.write("4\n");
if(radioButton_5->isChecked())
promo.write("5\n");
if(radioButton_6->isChecked())
promo.write("6\n");
if(radioButton_7->isChecked())
promo.write("7\n");
if(radioButton_8->isChecked())
promo.write("8\n");
if(radioButton_9->isChecked())
promo.write("9\n");


QString num = QVariant(spinBox1->value()).toString()+"\n";
 promo.write(num.toAscii().data()); //write spinbox value
promo.write(path.toAscii().data());   //write file name with path

promo.closeWriteChannel();promo.terminate();   //closing QProcess

}



Sorry for replying late ..... thanks again

This post has been edited 1 times, last edit by "ashwanijha" (Jul 2nd 2010, 1:10pm)


6

Friday, July 2nd 2010, 1:07pm

process.h

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#ifndef promotif_H
#define promotif_H
 
#include "ui_promo.h"
 
 
class promotif : public QWidget, private Ui::Promotif
{
    Q_OBJECT
 
public:
    promotif(QWidget *parent = 0);
 
 
public slots:
    void getPath();
    void run();
  

};
 
 
#endif





main.cpp

Source code

1
2
3
4
5
6
7
8
9
10
11
12
#include <QApplication>
 
#include "promo.h"
 
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    promotif *dialog = new promotif;
 
    dialog->show();
    return app.exec();
}

7

Wednesday, July 7th 2010, 12:17pm

I thought to using QProgressDialoge while process is running but the problem is it is still running even if qprogress stops ... please help .... any one .....

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <QtGui>
#include "promo.h"



promotif::promotif(QWidget *parent)
{


    setupUi(this); // this sets up GUI

    // signals/slots mechanism in action
    connect( pushButton_browse, SIGNAL( clicked() ), this, SLOT( getPath() ) );
    connect( pushButton_run, SIGNAL( clicked() ), this, SLOT( run() ) );
    connect( pushButton_about, SIGNAL( clicked() ), this, SLOT( about() ) );
    connect(pushButton_cancel,SIGNAL(clicked()),this,SLOT(cancel()));
}

  QString path;

void promotif::getPath()
{


    path = QFileDialog::getOpenFileName(
        this,
        "Choose a file to open",
        QString::null,
        QString::null);
    lineEdit->setText( path );
}


void promotif::run()
{

QProcess *promo = new QProcess();
            QString str;
    QString combo;

    QProgressDialog dlg ;
        dlg.setLabelText("Running ....");

        dlg.setRange(0,0);
        dlg.setValue(0);
connect(promo,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT());

 promo->start("a.exe");

promo->waitForStarted();


if(radioButton->isChecked())
    promo->write("1\n");
if(radioButton_2->isChecked())
    promo->write("2\n");
if(radioButton_3->isChecked())
    promo->write("3\n");
if(radioButton_4->isChecked())
    promo->write("4\n");
if(radioButton_5->isChecked())
promo->write("5\n");
if(radioButton_6->isChecked())
promo->write("6\n");
if(radioButton_7->isChecked())
promo->write("7\n");
if(radioButton_8->isChecked())
promo->write("8\n");
if(radioButton_9->isChecked())
promo->write("9\n");

QString num = QVariant(spinBox1->value()).toString()+"\n";
       promo->write(num.toAscii().data());
 promo->write(path.toAscii().data());


promo->closeWriteChannel();

dlg.exec();
//promo.finished();

   //dlg.setLabelText("complete...");
connect( promo, SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(stop()));
//promo.terminate();


}

Similar threads

Rate this thread