Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Refresh application GUI after running external application
Forum Updated to NodeBB v4.3 + New Features

Refresh application GUI after running external application

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 3.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    evanol
    wrote on last edited by evanol
    #1

    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?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      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()
      
      1 Reply Last reply
      0
      • E Offline
        E Offline
        evanol
        wrote on last edited by
        #3

        @ChrisW67

        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

        1 Reply Last reply
        0
        • E Offline
          E Offline
          evanol
          wrote on last edited by
          #4

          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 ) );
          }
          
          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved