English 中文(简体)
处理 :: terfate () 不使用简单的 Qt 应用程序作为 Windows XP 下的子进程
原标题:QProcess::terminate() doesn t work with simple Qt app as child process under Windows XP

首先,我简单的 Qt 应用程序, 我将从一个处理对象开始 :

#include <QtGui>

class LOLProcess : public QMainWindow {
    Q_OBJECT
public:
    LOLProcess(QWidget *parent = 0);
    ~LOLProcess();
protected:
    void closeEvent(QCloseEvent *);
};

LOLProcess::LOLProcess(QWidget *parent) : QMainWindow(parent) {
}
LOLProcess::~LOLProcess() {
    qDebug() << "~LOLProcess()";
}
void LOLProcess::closeEvent(QCloseEvent *) {
    qDebug() << "closeEvent()";
}

int main(int argc, char *argv[]) {
    QApplication a(argc, argv);
    LOLProcess w;
    w.show();
    return a.exec();
}

现在, Qt 应用程序与 Qprocess 对象:

#include <QtGui>

class MainWindow : public QMainWindow {
    Q_OBJECT
public:
    MainWindow(QWidget *parent = 0);
    QProcess process;
public slots:
    void close_down();
};

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
    process.start("../../lolprocess-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Release/release/lolprocess.exe");
    QTimer::singleShot(3000, this, SLOT(close_down()));
}

void MainWindow::close_down() {
    process.terminate();
    while (!process.waitForFinished(500)) {
    qDebug() << process.readAllStandardError();
    qDebug() << process.readAllStandardOutput();
    }
    qDebug() << process.waitForFinished(5000);
    qDebug() << (process.state() == QProcess::Running);
}

int main(int argc, char *argv[]) {
    QApplication a(argc, argv);
    QDir::setCurrent(QCoreApplication::applicationDirPath());
    MainWindow w;
    w.show();
    return a.exec();
}

行为 : 终止 () 导致子进程窗口消失( 从 XP 任务栏 ), 但此进程仍然按照任务栏运行 。 此时 < code> (! process. wait for finished (500)) 环会永远存在, 因为 QProcess 对象从未退出 () 。 令人惊讶的是, 我从子进程( 仅打印 < code_ process:: readallStandard... () 调用空字符串) 似乎很奇怪, 因为子进程顶端的窗口关闭让我觉得在子进程 中 接近 Event () 。

将儿童过程与 QProcess:: kill () work, 但我不想使用它, 因为它没有给儿童过程在离开前清理的机会 。

有趣的是,根据 Qt 4.7.4 和 OS X 10.6.x - 终止 (), 同样的代码在 Qt 4.7.4 和 OS X 10.6.x - 终止 () 下正确工作, 使得子进程可以干净地退出, 所以我不确定在 XP 下我做错了什么。 谢谢 。

最佳回答

现在尝试 :

#include <QtGui>

class LOLProcess : public QMainWindow {
    Q_OBJECT
public:
    LOLProcess(QWidget *parent = 0);
    ~LOLProcess();
protected:
    void closeEvent(QCloseEvent *);

public slots:
    void lastWindowClosed();
};

LOLProcess::LOLProcess(QWidget *parent) : QMainWindow(parent) {
}
LOLProcess::~LOLProcess() {
    qDebug() << "~LOLProcess()";
}
void LOLProcess::closeEvent(QCloseEvent *) {
    qDebug() << "closeEvent()";
}

void LOLProcess::lastWindowClosed (){
    QApplication::quit();
}

int main(int argc, char *argv[]) {
    QApplication a(argc, argv);
    LOLProcess w;
    QObject::connect(&a, SIGNAL(lastWindowClosed()), &w, SLOT(lastWindowClosed()));
    w.show();
    return a.exec();
}

这不应该是无稽之谈。在我有更多时间进一步调查的时候,似乎在qt中有些怪怪的怪怪的。

问题回答

暂无回答




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签