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 ....
Re: Running External c++ program when user hit ok button
Quote:
but i want the proc.write to be user defined from my gui ....
I'm not entirely sure what you mean by this -
but assuming that you want the user to dictate what gets written, you could simply catch user input in a QlineEdit or something similar and use its text as the arguement to the proc.write function.
Re: Running External c++ program when user hit ok button
I think what You want is argument handling/parsing, something like this: (first google hit) http://wwwx.cs.unc.edu/~sparkst/howto/cpp_main.php
Re: Running External c++ program when user hit ok button
i dont need to call external c++ program from c++ but i want to create a gui which will write to my program / executable
i know QProcess::start is good enough to start an external executable ... but i dont know how to write the value from radiobutton to my process ...
i m good in c++ i dont need argument handling/parsing but i want to create stand alone or gui to make my program user friendly .... I am in scientific lab now i want that people can use my programe with ease ..
I Need to create a GUI ... thanks
Re: Running External c++ program when user hit ok button
Quote:
i know QProcess::start is good enough to start an external executable ... but i dont know how to write the value from radiobutton to my process ...
I read Your posts three times and don't quite get what is Your problem, but if You want to pass arguments to You external program depending on the radiobutton state then do something like this:
Code:
if( ui->radioButton->isChecked() )
proc.write("3\n");
if( ui->radioButton2->isChecked() )
proc.write("7\n");
then place this code in i.e. pushbutton, or whatever place You execute You external program, and depending on the radiobutton state these argument will be sent. Also You mentioned:
Quote:
proc.write("7\n"); // input from a radio button as i have need integer between 1-9 as cut off
I think beter for this purpouse will be QSpinBox (setup it so min val = 1, and max = 9), somthing like this [draft code didn't tested it]:
Best regards
Re: Running External c++ program when user hit ok button
QString str = QVariant( ui->spinBox->value() ).toString() + "\n";
proc.write( str );
thanks :cool: Talei thats what i am lookin for ....
Thank you so much
well i want to run an external executable (exe or ./exe) from qt ;) never mind ....
just one more help plz ... how to upload file in qt ....
Re: Running External c++ program when user hit ok button
You are welcome,
As for the upload, You didn't specified wher to upload. Is it ftp,www with custom php upload script, depending on these the approach is different.
For ftp use QFtp, look i.e. here http://www.qtcentre.org/threads/3050...-is-not-called
For WWW QNetworkClasses with reply etc.., if it's custom php script sniff packet header content then prepare appropriate header and send it from Your application.
Best luck
Re: Running External c++ program when user hit ok button
solved i got the correct code ill post the codes hope some one will get benifited by the code
Re: Running External c++ program when user hit ok button
main .cpp
Code:
#include <QApplication>
#include "promo.h"
int main(int argc, char *argv[])
{
myQtApp *dialog = new myQtApp;
dialog->show();
return app.exec();
}
process.pro
Code:
HEADERS = promo.h
SOURCES = promo.cpp main.cpp
FORMS = promo.ui
# install
target.path = promo
sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.pro
sources.path = .
INSTALLS += target sources
Re: Running External c++ program when user hit ok button
process.h header file
Code:
#ifndef MYQTAPP_H
#define MYQTAPP_H
#include "ui_promo.h"
class myQtApp
: public QWidget,
private Ui
::myQtAppDLG{
Q_OBJECT
public:
public slots:
void getPath();
void run();
void about();
};
#endif
1 Attachment(s)
Re: Running External c++ program when user hit ok button
proocess.cpp main cpp file
Code:
#include <QtGui>
#include "promo.h"
{
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() ) );
}
void myQtApp::getPath() //browse button
{
this,
"Choose a file to open",
lineEdit->setText( path );
}
void myQtApp::run() //to run process
{
int value1;
promo.start("a.exe"); //my c++ compiled executable
promo.waitForStarted();
if(radioButton->isChecked()) //writing radio button values
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");
QString num
= QVariant(spinBox1
->value
()).
toString()+"\n";
//spin box value to string called num promo.write(num.toAscii().data()); //writing to QBytearrya ie convert from string to array
promo.write(path.toAscii().data());
promo.closeWriteChannel(); //closing write channel
promo.waitForFinished();
}
void myQtApp::about() //about button
{
"is running\n"
);
}
Thanks to http://sector.ynet.sk/qt4-tutorial/ and Talei :) thanks