Refresh application GUI after running external application
-
Hello,
I'm looking for some advice on how to refresh/redraw my main application after running an external application.
Currently I'm doing the following:
QProcess systemCall; systemCall.start( externalAppPath, externalAppArgs ); systemCall.waitForFinished( -1 ); //wait indefinitely for process to finish systemCall.close(); QWidget *qwParent = this; while( (qwParent) ) { qDebug() << "repainting parent :" << qwParent; qwParent->repaint(); qwParent = qwParent->parentWidget(); qDebug() << "next parent :" << qwParent; }
As one of the options in my main application I have to launch our external application and wait for it to finish.
On exiting the external application and returning to my main app I need to repaint all parent widgets using the above while loop.My question is - is there a better way of achieving this?
-
On exiting the external application and returning to my main app I need to repaint all parent widgets using the above while loop.
My question is - is there a better way of achieving this?What is wrong with just letting your program return to the event loop? Even better, never block the event loop in the first place. If you absolutely cannot do that then QCoreApplication::processEvents().
You should not call QWidget::repaint() (as described in the docs), call QWidget::update() instead.
This is a better way to do the loop, but you should never need to do this.
foreach (QWidget *widget, QApplication::topLevelWidgets()) { widget->update(); } QCoreApplication::processEvents()
-
See linked image when I launch my external application without blocking the main app. I get the following:
https://www.dropbox.com/s/ffm2lc2192pavdq/IMG_20150706_111143.jpg?dl=0
With the above code I am trying to prevent this occurring.Also, when using the external application, the user should not be interacting with the main application so I felt that waiting for the external application to finish was the best option.
I am open to any/all suggestions on how to achieve this in a better way.
Thanks -
I've updated my code to call the following QDialog which negates the need to manually update parent widgets.
Any comments/feedback welcome...
#include "externalAppdialog.h" #include "ui_externalAppdialog.h" externalAppDialog::externalAppDialog(QWidget *parent) : QDialog(parent), ui(new Ui::externalAppDialog) { ui->setupUi(this); this->setWindowFlags( Qt::FramelessWindowHint ); connect( this, SIGNAL( finished( int ) ), this, SLOT( deleteLater() ) ); this->showFullScreen(); activityTicker = new QTimer( this ); connect( activityTicker, SIGNAL( timeout() ), this, SLOT( keepMainAppAlive() ) ); activityTicker->setInterval( (30 * 1000) ); //every 30s; systemCall = new QProcess( this ); connect( systemCall, SIGNAL( finished(int) ), this, SLOT( accept() ) ); connect( systemCall, SIGNAL( finished(int) ), activityTicker, SLOT( stop() ) ); QTimer::singleShot( 0, this, SLOT( launchexternalAppApp() ) ); } externalAppDialog::~externalAppDialog() { delete ui; } void externalAppDialog::launchexternalAppApp( void ) { systemCall->start( QString( "%1/%2" ) .arg( "externalAppPath" ) .arg( "externalApp" ), QStringList() << "-qws" ); activityTicker->start(); } void externalAppDialog::keepMainAppAlive( void ) { qApp->postEvent( this, new QEvent( QEvent::MouseMove ) ); }