Results 1 to 11 of 11

Thread: Running External c++ program when user hit ok button

  1. #1
    Join Date
    May 2010
    Posts
    11
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Post 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 ....


  2. #2
    Join Date
    Oct 2009
    Posts
    151
    Thanks
    6
    Thanked 13 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Running External c++ program when user hit ok button

    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.

  3. #3
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default 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

  4. #4
    Join Date
    May 2010
    Posts
    11
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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

  5. #5
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Running External c++ program when user hit ok button

    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:

    Qt Code:
    1. if( ui->radioButton->isChecked() )
    2. proc.write("3\n");
    3. if( ui->radioButton2->isChecked() )
    4. proc.write("7\n");
    To copy to clipboard, switch view to plain text mode 
    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:
    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]:
    Qt Code:
    1. QString str = QVariant( ui->spinBox->value() ).toString() + "\n";
    2. proc.write( str );
    To copy to clipboard, switch view to plain text mode 

    Best regards
    Last edited by Talei; 6th May 2010 at 18:51.

  6. The following user says thank you to Talei for this useful post:

    Ashwani (7th May 2010)

  7. #6
    Join Date
    May 2010
    Posts
    11
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Talking Re: Running External c++ program when user hit ok button

    QString str = QVariant( ui->spinBox->value() ).toString() + "\n";
    proc.write( str );

    thanks 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 ....
    Last edited by Ashwani; 7th May 2010 at 11:58.

  8. #7
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default 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

  9. The following user says thank you to Talei for this useful post:

    Ashwani (2nd July 2010)

  10. #8
    Join Date
    May 2010
    Posts
    11
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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

  11. #9
    Join Date
    May 2010
    Posts
    11
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Running External c++ program when user hit ok button

    main .cpp
    Qt Code:
    1. #include <QApplication>
    2.  
    3. #include "promo.h"
    4.  
    5. int main(int argc, char *argv[])
    6. {
    7. QApplication app(argc, argv);
    8. myQtApp *dialog = new myQtApp;
    9.  
    10. dialog->show();
    11. return app.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 



    process.pro
    Qt Code:
    1. HEADERS = promo.h
    2. SOURCES = promo.cpp main.cpp
    3. FORMS = promo.ui
    4.  
    5. # install
    6. target.path = promo
    7. sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.pro
    8. sources.path = .
    9. INSTALLS += target sources
    To copy to clipboard, switch view to plain text mode 
    Last edited by Ashwani; 1st July 2010 at 13:48.

  12. #10
    Join Date
    May 2010
    Posts
    11
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Running External c++ program when user hit ok button

    process.h header file

    Qt Code:
    1. #ifndef MYQTAPP_H
    2. #define MYQTAPP_H
    3.  
    4. #include "ui_promo.h"
    5.  
    6.  
    7. class myQtApp : public QWidget, private Ui::myQtAppDLG
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. myQtApp(QWidget *parent = 0);
    13.  
    14.  
    15. public slots:
    16. void getPath();
    17. void run();
    18. void about();
    19.  
    20. };
    21.  
    22.  
    23. #endif
    To copy to clipboard, switch view to plain text mode 
    Last edited by Ashwani; 1st July 2010 at 13:48.

  13. #11
    Join Date
    May 2010
    Posts
    11
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Running External c++ program when user hit ok button

    proocess.cpp main cpp file

    Qt Code:
    1. #include <QtGui>
    2. #include "promo.h"
    3.  
    4.  
    5.  
    6. myQtApp::myQtApp(QWidget *parent)
    7. {
    8. setupUi(this); // this sets up GUI
    9.  
    10. // signals/slots mechanism in action
    11. connect( pushButton_browse, SIGNAL( clicked() ), this, SLOT( getPath() ) );
    12. connect( pushButton_run, SIGNAL( clicked() ), this, SLOT( run() ) );
    13. connect( pushButton_about, SIGNAL( clicked() ), this, SLOT( about() ) );
    14. }
    15.  
    16. QString path;
    17. void myQtApp::getPath() //browse button
    18. {
    19.  
    20.  
    21. path = QFileDialog::getOpenFileName(
    22. this,
    23. "Choose a file to open",
    24. QString::null,
    25. QString::null);
    26. lineEdit->setText( path );
    27. }
    28.  
    29. void myQtApp::run() //to run process
    30. {
    31.  
    32. int value1;
    33. QString str;
    34. QString combo;
    35.  
    36.  
    37. QProcess promo;
    38. promo.start("a.exe"); //my c++ compiled executable
    39. promo.waitForStarted();
    40.  
    41.  
    42. if(radioButton->isChecked()) //writing radio button values
    43. promo.write("1\n");
    44. if(radioButton_2->isChecked())
    45. promo.write("2\n");
    46. if(radioButton_3->isChecked())
    47. promo.write("3\n");
    48. if(radioButton_4->isChecked())
    49. promo.write("4\n");
    50.  
    51. QString num = QVariant(spinBox1->value()).toString()+"\n"; //spin box value to string called num
    52. promo.write(num.toAscii().data()); //writing to QBytearrya ie convert from string to array
    53. promo.write(path.toAscii().data());
    54.  
    55.  
    56. promo.closeWriteChannel(); //closing write channel
    57. promo.waitForFinished();
    58.  
    59. }
    60.  
    61.  
    62.  
    63.  
    64. void myQtApp::about() //about button
    65. {
    66. QMessageBox::about(this,"About Promotif",
    67. "is running\n"
    68. );
    69. }
    To copy to clipboard, switch view to plain text mode 
    Thanks to http://sector.ynet.sk/qt4-tutorial/ and Talei thanks
    Attached Images Attached Images
    Last edited by Ashwani; 1st July 2010 at 13:49.

Similar Threads

  1. Replies: 1
    Last Post: 30th April 2010, 13:25
  2. running external console program by gui program
    By alireza.mixedreality in forum Qt Programming
    Replies: 4
    Last Post: 24th April 2010, 18:05
  3. running external applications via QT?
    By cruisx in forum Newbie
    Replies: 1
    Last Post: 11th August 2009, 06:34
  4. Replies: 7
    Last Post: 19th January 2008, 15:29
  5. Replies: 1
    Last Post: 17th May 2006, 00:23

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.