c++ - Outputting QProcess readAll response to label -
i have qprocess output response in label. first off, here have tried:
qprocess *proc = new qprocess(); proc->setprocesschannelmode(qprocess::mergedchannels); proc->start(cmdlinerequest.toutf8().constdata()); // cmdlinerequest omitted if (!proc->waitforfinished()) { qdebug() << "make failed:" << proc->errorstring(); ui->topbarcode->settext(qstring(proc->errorstring())); } else { qdebug() << "make output:" << proc->readall(); ui->topbarcode->settext(qstring(proc->readall()) + "asdf"); } proc->readall() qbytearray , settext accepts qstring. i've read, should able cast qbytearray qstring, howver not work. have tried convert proc->readall() qstring class
->settext(qstring::fromutf8(proc->readall())) // not working ->settext(qstring::fromlatin1(proc->readall())) // not working ->settext(qstring::fromlocal8bit(proc->readall())) // not working ... etc ... it seems weird, since i'm adding pictures labels in same matter using setpixmap(qpixmap::fromimage(image))
any appreciated, thank you.
update:
if add qmessagebox before end of method above block of code belongs to, can see text added label. when close qmessagebox, text dissapears. giving address position label proc->readall() or how come behaviour? thank you.
the problem here you're calling proc->readall twice; first qdebug output , again string set on label.
{ qdebug() << "make output:" << proc->readall(); ui->topbarcode->settext(qstring(proc->readall()) + "asdf"); } i expect qprocess qiodevice, it's returning buffered byte array. when read it, removes buffer.
therefore, create temporary string , read buffer once, before calling qdebug , setting string label: -
{ qstring output = proc->readall(); qdebug() << "make output:" << output; ui->topbarcode->settext(output + "asdf"); }
Comments
Post a Comment