qt - QProcess read and write -
i trying read , write qprocess right now. made little test program takes input , redisplays on screen in loop. here code qt
qstring path = "./test"; tcd = new qprocess(this); qstringlist args; args << ""; tcd->start(path,args); if(!tcd->waitforstarted(3000)) { stdoutput->append("<h1><font color=red>there problem starting software, please try running program again.</font></h1>"); } tcd->write("hello\n"); tcd->write("hello\n"); tcd->write("hello\n"); tcd->write("hello\n"); //tcd->write("quit\n"); qobject::connect(tcd, signal(readyreadstandardoutput()), this, slot(appendtextbox()));
this won't work unless send last quit command (which terminates test program).
here's read command:
void tcd2_gui::appendtextbox(){ stdoutput->append("new output available: \n"); qbytearray newdata = tcd->readallstandardoutput(); stdoutput->append(qstring::fromlocal8bit(newdata)); }
if send quit, output program @ once, including have sent it.
what doing wrong here?
as per request, here code program:
int main(int argc[], char* argv[]){ printf("welcome!\n"); char* input = malloc(160); gets(input); while(strcmp(input,"quit") != 0) { printf("got input %s\n", input); gets(input); } }
from doc:
certain subclasses of qiodevice, such qtcpsocket , qprocess, asynchronous. means i/o functions such write() or read() return immediately, while communication device may happen when control goes event loop. qiodevice provides functions allow force these operations performed immediately, while blocking calling thread , without entering event loop.
...
waitforbyteswritten() - function suspends operation in calling thread until 1 payload of data has been written device.
...
calling these functions main, gui thread, may cause user interface freeze.
Comments
Post a Comment