[Qt-interest] qprocess related with qprogressbar

mierdatutis mi mmm286 at gmail.com
Sat Jun 27 11:47:05 CEST 2009


Many thanks Sean but I try to follow your instructions and it gives me an
error when I do progress->show(); when the process started.I do:

Mainwindowimpl.sh

 class MainWindowImpl : public QMainWindow, public Ui::MainWindow

{

Q_OBJECT

public:

MainWindowImpl( QWidget * parent = 0, Qt::WFlags f = 0 );

private slots:

void cambio(QListWidgetItem*);

void salida();

void empieza();

private:

QProcess *proc2;

* QProgressDialog *progress;*

};

#endif


mainwindowimpl.cpp




MainWindowImpl::MainWindowImpl( QWidget * parent, Qt::WFlags f)

: QMainWindow(parent, f)

{

setupUi(this);

proc2 = new QProcess( this );

QProgressDialog *progress = new QProgressDialog( this );

progress->setWindowModality(Qt::WindowModal);

progress->setRange(0,100);

progress->setValue(0);

.................

.......................



connect(proc2, SIGNAL(readyReadStandardOutput()),this, SLOT(salida()));

connect(lista, SIGNAL( itemClicked(QListWidgetItem*) ), this,
SLOT(cambio(QListWidgetItem*) ) );

* connect(proc2, SIGNAL(started()),this, SLOT(empieza()));*

}




void MainWindowImpl::empieza()

{

*progress->show(); THIS, I HAVE THE ERROR (SEGMENTATION FAULT)*

}



void MainWindowImpl::cambio(QListWidgetItem * item )

{

QString str=lista->currentItem()->text();

qDebug() << lista->currentItem()->text();

proc2->start("/home/david/seguridad/verdadero/pruebon.sh",QStringList() <<
str );

}

 void MainWindowImpl::salida()

{


  if ( line.compare("hola",Qt::CaseInsensitive)) {

qDebug() << " NO HEMOS ENTRADO";

}

else {

qDebug() << "ENTRADO";

  progress->setValue(10);

 }

  if ( line.compare("hola2",Qt::CaseInsensitive)) {

qDebug() << " NO HEMOS ENTRADO";

}

else {

qDebug() << "ENTRADO";

progress->setValue(30);

}

.....................
.....................

I don't know what it's wrong? Some help? Many thanks again







2009/6/27 Sean Harmer <sean.harmer at maps-technology.com>

> Hi,
> mierdatutis mi wrote:
> > Many thanks again.
> > I put in my shell script, some outpouts to stdout that the function
> > that read all the output of the script can compare the string and can
> > increment the progress bar.
> > The problem that I have is that the progressbardialog dissapear every
> > time that the program enter in the output capture. Could I do that the
> > progressbar is always on top?
> >
> > Many thanks
> >
> > This is the code:
> >
> > void MainWindowImpl::salida()
> > {
> >       QStringList strs;
> >
> >     QByteArray result=proc2->readAllStandardOutput();
> >     qDebug() << proc2->readAllStandardOutput();
> >
> >     QStringList lines = QString(result).split("\n");
> >     foreach (QString line, lines) {
> >         texto->append(line);
> >         qDebug() << line;
> >
> >     QProgressDialog progress("DESCARANDO SINOPSIS...", "&Wake Up!", 0, 7,
> 0);
> >
> This is your problem. You are creating a QProgressDialog on the stack so
> that when the execution reaches the end of this function and the stack
> is cleaned up the dialog will get destroyed.
>
> Instead what you could do it make pointer to a QProgressDialog a member
> of your class, create it either in the constructor but do not show it at
> this point. Show it from a slot that gets called when the process has
> started. Then call setValue in your slot that processes the output of
> your script. If you create the progress dialog with your main window as
> its parent, then their is no need to ever explicitly delete it as the Qt
> object model will do this for you. However, you will need to hide the
> dialog when the process finishes. Once again this can be done in a slot
> connected to the QProcess::finished() signal.
>
> Good luck,
>
> Sean
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090627/54b61e2f/attachment.html 


More information about the Qt-interest-old mailing list