Results 1 to 2 of 2

Thread: Connecting qprocess and qprogressdialogue

  1. #1
    Join Date
    Dec 2011
    Living in Spain 100km North of Valencia
    Qt products

    Default Connecting qprocess and qprogressdialogue

    I am having a problem with something that is so blindingly obvious I can't see it!
    I want to connect a running external process to a progress dialogue that closes when the process finishes, or by pressing the cancel button on the dialogue stops the process.
    Program so far:

    Qt Code:
    1. void MP3collection::normalise()
    2. {
    3. if ( check4normalise() )
    4. {
    5. infoWarnError(INFORMATION, nice("Normalise"), nice(QString("%1 already normalised").
    6. arg(ui->lbl_selection->text())));
    7. return;
    8. }
    9. QString file, cmd;
    10. QProcess *proc = new QProcess(this);
    11. QProgressDialog *dlg = new QProgressDialog("Normalisation", "Cancel",0,0);
    12. dlg->setModal(Qt::WindowModal);
    13. file = QString("%1/%2.mp3").arg(currentDir, ui->lbl_selection->text());
    14. cmd = "lame";
    15. args.append("--scale");
    16. args.append("2");
    17. args.append(file);
    18. args.append(tmpFile);
    19. proc->start(cmd, args);
    20. connect(proc, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(procEnd(int)));
    21. // proc->waitForFinished(); /// Including this leaves blank previous dialogues.
    22. dlg->exec();
    23. connect(proc, SIGNAL(finished(int)), dlg, SLOT(close())); /// These don't seem to work
    24. connect(dlg, SIGNAL(finished(int)), proc, SLOT(kill())); /// ditto
    25. }
    27. void MP3collection::procEnd(int i)
    28. {
    29. //It would be nice to close the dialogue here but it doesn't know about [I]dlg[/I] of course.
    30. qDebug()<<i;
    31. // close();
    32. }
    To copy to clipboard, switch view to plain text mode 

    The program runs and the process works as expected. I cannot stop the process and the dialogue remains after the process has finished requiring the cancel button.

    Any advice would be much appreciated.
    Thanks in advance

  2. #2
    Join Date
    Jan 2006
    Graz, Austria
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Unix/X11 Windows

    Default Re: Connecting qprocess and qprogressdialogue

    Quote Originally Posted by GrahamB View Post
    Qt Code:
    1. dlg->exec();
    2. connect(proc, SIGNAL(finished(int)), dlg, SLOT(close())); /// These don't seem to work
    3. connect(dlg, SIGNAL(finished(int)), proc, SLOT(kill())); /// ditto
    To copy to clipboard, switch view to plain text mode 
    1) Why connect after the dialog has finished?
    You want these connections to be available while the dialog is active.

    2) There is no such signal in QProcess
    3) There is no such signal in QProgressDialog


Similar Threads

  1. QProcess crashes second QProcess
    By Ion in forum Newbie
    Replies: 1
    Last Post: 23rd September 2014, 22:00
  2. Replies: 1
    Last Post: 3rd June 2013, 14:11
  3. Replies: 0
    Last Post: 23rd March 2013, 20:23
  4. Replies: 0
    Last Post: 26th August 2010, 11:44
  5. Connecting with QProcess to an already running process
    By high_flyer in forum Qt Programming
    Replies: 7
    Last Post: 26th November 2007, 11:31


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.