VirtualBox

Changeset 11387 in vbox for trunk


Ignore:
Timestamp:
Aug 13, 2008 1:08:27 PM (16 years ago)
Author:
vboxsync
Message:

Fe/Qt4: Own QProcess implementation to avoid Qt4 (4.3.x version) bug concerning QProcess blocks the GUI thread due to didn't get process-finished inner notification. This object will be used in Registration & New Version Notifier dialog.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox4/include/VBoxGlobal.h

    r10728 r11387  
    3535#include <QMenu>
    3636#include <QStyle>
     37#include <QProcess>
    3738
    3839class QAction;
     
    160161
    161162    const QString mLangId;
     163};
     164
     165class Process : public QProcess
     166{
     167    Q_OBJECT;
     168
     169public:
     170
     171    static QByteArray singleShot (const QString &aProcessName,
     172                                  int aTimeout = 5000
     173                                  /* wait for data maximum 5 seconds */)
     174    {
     175        /* Why is it really needed is because of Qt4.3 bug with QProcess.
     176         * This bug is about QProcess sometimes (~70%) do not receive
     177         * notification about process was finished, so this makes
     178         * 'bool QProcess::waitForFinished (int)' block the GUI thread and
     179         * never dismissed with 'true' result even if process was really
     180         * started&finished. So we just waiting for some information
     181         * on process output and destroy the process with force. Due to
     182         * QProcess::~QProcess() has the same 'waitForFinished (int)' blocker
     183         * we have to change process state to QProcess::NotRunning. */
     184
     185        QByteArray result;
     186        Process process;
     187        process.start (aProcessName);
     188        bool firstShotReady = process.waitForReadyRead (aTimeout);
     189        if (firstShotReady)
     190            result = process.readAllStandardOutput();
     191        process.setProcessState (QProcess::NotRunning);
     192        return result;
     193    }
     194
     195protected:
     196
     197    Process (QWidget *aParent = 0) : QProcess (aParent) {}
    162198};
    163199
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette