PDA

View Full Version : QProcess



jaca
14th May 2008, 19:16
The code below in this SIGNAL clicked () a QPushButton. Every time I change the file mpl.tex I click the Button to update the file mpl.pdf, but this update only happens when click twice the Button. In the first click it shows the mpl.pdf old and the second click it updates.



QProcess *latexfile = new QProcess;
latexfile->start("latex", QStringList() << "mpl.tex");
QProcess *psfile = new QProcess;
psfile->start("dvips", QStringList() << "-ta4" << "-o" << "mpl.ps" << "mpl.dvi");
QProcess *pdffile = new QProcess;
pdffile->start("ps2pdf", QStringList() << "mpl.ps" << "mpl.pdf");
QProcess *openpdf = new QProcess;
openpdf->start("/usr/bin/acroread", QStringList() << "mpl.pdf");


Somebody has idea of as to make this?
Thanks.

wysota
14th May 2008, 21:31
QProcess works asynchronously, so if you want to start a chain of commands, you can't do it like this. You have to wait until one commands finishes its execution before starting the next.

jaca
14th May 2008, 21:52
I delete the files mpl.dvi, mpl.ps and mpl.pdf. Modify the file mpl.tex open the program click on Button, who has the code below, and it shows that the mpl.pdf delete previously. I do not understand. This file is updated only when mpl.pdf click for the second time the Button.


void Mpl::openPdf()
{
QProcess *latexfile = new QProcess;
QProcess *psfile = new QProcess;
QProcess *pdffile = new QProcess;
QProcess *openpdf = new QProcess;

latexfile->start("latex",QStringList() << "mpl.tex");
if (latexfile->waitForStarted())
cout << "Erro" << endl;
psfile->start("dvips", QStringList() << "-ta4" << "-o" << "mpl.ps" << "mpl.dvi");
pdffile->start("ps2pdf", QStringList() << "mpl.ps" << "mpl.pdf");
openpdf->start("/usr/bin/acroread", QStringList() << "mpl.pdf");
}

Somebody can help me, please?:confused:

jaca
15th May 2008, 02:18
QProcess works asynchronously, so if you want to start a chain of commands, you can't do it like this. You have to wait until one commands finishes its execution before starting the next.

Do not understand very well, I have to wait a while? How do this? How do I know whether the execution has ended?

wysota
15th May 2008, 08:41
Take a look at QProcess API and see what signals it emits. Also I suggest reading all its docs and taking a look at examples if there are any. Anyway in your case I'd suggest using system() instead of QProcess, at least for some of the calls.

jaca
15th May 2008, 11:24
Anyway in your case I'd suggest using system() instead of QProcess, at least for some of the calls.

Really I did. Thanks.