c++ - How to avoid waitForStarted with QProcess to stop GUI from freezing? -
i running wscript qprocess run vb script converts excel files tab delimited text files. script runs fine , everything, gui freezes , user unable interact significant amount of time. here code:
/* create txt files , store paths */ (int = 0; < excelfilepaths.size(); ++i) { wscript->start("wscript.exe", qstringlist() << vbs.filename() << excelfilepaths.at(i) << newdir.absolutepath() + "/" + qstring::number(i + 1)); wscript->waitforfinished(); payloadpaths.push_back(newdir.absolutepath() + "/" + qstring::number(i + 1)); }
so whats going on have multiple excel file paths , qprocess allocated on heap. qprocess runs vb script converts excel files text files , stores path of new text file. takes long time (about 20 seconds 4 excel files). during time gui frozen. user able use parts of gui don't interfere process.
now suspect cause of issue is
qprocess::waitforfinished()
and i've read online connecting finished() , error() signals of qprocess remove problem. i've been having difficulty doing so. i'm running code method of class inherits qobject , containst q_object macro, should set. need putting rest of pieces together. how can make gui not freeze while qprocess running? please help.
to quote documentation @ section called synchronous process api:
waitforstarted()
blocks until process has started.waitforreadyread()
blocks until new data available reading on current read channel.waitforbyteswritten()
blocks until 1 payload of data has been written process.waitforfinished()
blocks until process has finished.calling these functions main thread (the thread calls qapplication::exec()) may cause user interface freeze.
keep in mind. may overcome issue using that:
connect(process, static_cast<void(qprocess::*)(int, qprocess::exitstatus)>(&qprocess::finished), [=](int exitcode, qprocess::exitstatus exitstatus){ /* ... */ });
note there more signals may suite desired purpose.
Comments
Post a Comment