qprocess - Need to quit a process from inside Qt GUI, just as it is started -


i trying run c++ executables placed inside sbc6845 [inside /ftest shown ]. these executables running with

while(1){ // around 250-300 lines of code here } 

infinite loop. when run codes terminal, can kill them whenever want to. unable kill them while running inside gui. execute these codes qprocess this:

mainwindow::mainwindow(qwidget *parent) : qmainwindow(parent), ui(new ui::mainwindow){ ui->setupui(this);  connect(ui->pushbutton, signal(pressed()), slot(vcm_test())); connect(ui->pushbutton_2, signal(pressed()), slot(offloader_test())); connect(ui->pushbutton_3, signal(pressed()), slot(quit_vcm())); connect(ui->pushbutton_4, signal(pressed()), slot(quit_offloader()));} void mainwindow::vcm_test(){    qprocess::execute("/ftest/vcm_test_2 \r\n"); } void mainwindow::offloader_test(){     qprocess::execute("/ftest/off_test_2 \r\n"); }   void mainwindow::quit_vcm(){     qprocess::execute("\x001a \r\n"); }  void mainwindow::quit_offloader(){     qprocess::execute("\x001a \r\n");    } 

now problem when pushbutton or pushbutton_2 i.e. vcm_test() or offloader_test() invoked gui becomes unresponsive. since gui keeps waiting code in /ftest finish quit option not work , have quit terminal again. quitting terminal closes both code , gui.

i have tried searching solutions , used threads too. segmentation error while starting thread pushbutton.

i need able quit process while being executed (modification of code or new idea appreciated). newbie please ignore poor coding skills. thanks.

qprocess::execute(..) waits process finish, why gui freezing. use qprocess::start(..) instead. quit process use qprocess::close() function

try this:

qprocess *myprocess = new qprocess(this); myprocess->start("/ftest/vcm_test_2"); 

and when want close process:

myprocess->close(); 

you can connect pushbutton's clicked signal process' kill slot:

connect(ui->pushbutton_3, signal(clicked()), myprocess, slot(kill()); 

Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -