source:
vbox/trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIProcess.cpp
Last change on this file was 100064, checked in by , 15 months ago | |||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|||||||||||||||||||||||||||||||
File size: 2.3 KB |
Line | |
---|---|
1 | /* $Id: QIProcess.cpp 100064 2023-06-04 09:10:01Z vboxsync $ */ |
2 | /** @file |
3 | * VBox Qt GUI - Qt extensions: QIProcess class implementation. |
4 | */ |
5 | |
6 | /* |
7 | * Copyright (C) 2006-2023 Oracle and/or its affiliates. |
8 | * |
9 | * This file is part of VirtualBox base platform packages, as |
10 | * available from https://www.virtualbox.org. |
11 | * |
12 | * This program is free software; you can redistribute it and/or |
13 | * modify it under the terms of the GNU General Public License |
14 | * as published by the Free Software Foundation, in version 3 of the |
15 | * License. |
16 | * |
17 | * This program is distributed in the hope that it will be useful, but |
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
20 | * General Public License for more details. |
21 | * |
22 | * You should have received a copy of the GNU General Public License |
23 | * along with this program; if not, see <https://www.gnu.org/licenses>. |
24 | * |
25 | * SPDX-License-Identifier: GPL-3.0-only |
26 | */ |
27 | |
28 | /* GUI includes: */ |
29 | #include "QIProcess.h" |
30 | |
31 | /* External includes: */ |
32 | #ifdef VBOX_WS_NIX |
33 | # include <sys/wait.h> |
34 | #endif |
35 | |
36 | |
37 | QIProcess::QIProcess(QObject *pParent /* = 0 */) |
38 | : QProcess(pParent) |
39 | { |
40 | } |
41 | |
42 | /* static */ |
43 | QByteArray QIProcess::singleShot(const QString &strProcessName, int iTimeout /* = 5000 */) |
44 | { |
45 | // WORKAROUND: |
46 | // Why is it really needed is because of Qt4.3 bug with QProcess. |
47 | // This bug is about QProcess sometimes (~70%) do not receive |
48 | // notification about process was finished, so this makes |
49 | // 'bool QProcess::waitForFinished (int)' block the GUI thread and |
50 | // never dismissed with 'true' result even if process was really |
51 | // started&finished. So we just waiting for some information |
52 | // on process output and destroy the process with force. Due to |
53 | // QProcess::~QProcess() has the same 'waitForFinished (int)' blocker |
54 | // we have to change process state to QProcess::NotRunning. |
55 | |
56 | /// @todo Do we still need this? |
57 | QByteArray result; |
58 | QIProcess process; |
59 | process.start(strProcessName); |
60 | bool firstShotReady = process.waitForReadyRead(iTimeout); |
61 | if (firstShotReady) |
62 | result = process.readAllStandardOutput(); |
63 | process.setProcessState(QProcess::NotRunning); |
64 | #ifdef VBOX_WS_NIX |
65 | int iStatus; |
66 | if (process.processId() > 0) |
67 | waitpid(process.processId(), &iStatus, 0); |
68 | #endif /* VBOX_WS_NIX */ |
69 | return result; |
70 | } |
Note:
See TracBrowser
for help on using the repository browser.