Results 1 to 11 of 11

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

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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.

  2. #2
    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
  •  
Qt is a trademark of The Qt Company.