QX11EmbedContainer和QProcess问题

发布于 2024-07-10 19:34:57 字数 564 浏览 7 评论 0原文

我一直在尝试将 QX11EmbedContainer 放入我的应用程序中,并且我需要在其中启动一个终端(因为使用 konsolepart 我几乎什么也做不了)。

QX11EmbedContainer* container = new QX11EmbedContainer(this); // with or without "this" I got the same result
container->show(); 
QProcess process(container);
QString executable("xterm -into ");
QStringList arguments;
arguments << QString::number(container->winId());
process.start(executable, arguments);

编译顺利,但我收到了这条消息:

QProcess: Destroyed while process is still running.

我看不到容器,建议?????? 谢谢

I've been trying to put a QX11EmbedContainer in my app, and I need to start a terminal within it (because with konsolepart I can practically do nothing).

QX11EmbedContainer* container = new QX11EmbedContainer(this); // with or without "this" I got the same result
container->show(); 
QProcess process(container);
QString executable("xterm -into ");
QStringList arguments;
arguments << QString::number(container->winId());
process.start(executable, arguments);

compilation goes fine,but I got this message:

QProcess: Destroyed while process is still running.

and I'm not able to see the container, suggestions?????? Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白色秋天 2024-07-17 19:34:57

QProcess 在堆栈上分配,一旦超出范围就会被删除。 这很可能发生在“xterm”子进程退出之前(因此是输出)。

尝试在堆中分配 QProcess:

QProcess * process = new QProcess(container);
...
process->start(executable, arguments);

您可以通过三种方式删除 QProcess:

  1. 不执行任何操作。 让 QX11EmbedContainer 删除它。 它是 QX11EmbedContainer 的子级,并且会在删除 QX11EmbedContainer 时被删除。

  2. finished() 信号连接到其自己的 deleteLater() 槽。

    connect( process, SIGNAL(finished(int,QProcess::ExitStatus)), process, SLOT(deleteLater()) );

  3. 通过保留指向它的指针来删除它并删除该指针稍后。

作为额外说明,我对 QProcess::start() 的第一个参数表示怀疑。 它应该是可执行文件的路径,并且应将更多参数添加到 QStringlist 中。

QProcess * process = new QProcess(container);
QString executable("xterm"); // perhaps try "/usr/X11/bin/xterm"
QStringList arguments;
arguments << "-into";
arguments << QString::number(container->winId());
proces->start(executable, arguments);

The QProcess is allocated on the stack and will deleted as soon as it goes out of scope. This is likely to happen before the the "xterm" child process quits (hence the output).

Try allocating the QProcess in the heap instead:

QProcess * process = new QProcess(container);
...
process->start(executable, arguments);

You can delete the QProcess in three ways:

  1. Do nothing. Let the QX11EmbedContainer delete it. It is a child of the QX11EmbedContainer and will be deleted when the QX11EmbedContainer is deleted.

  2. Hook up the finished() signal to its own deleteLater() slot.

    connect( process, SIGNAL(finished(int,QProcess::ExitStatus)), process, SLOT(deleteLater()) );

  3. Delete it yourself by retaining a pointer to it and delete that pointer later.

As an extra note, I'm suspicious of the first parameter to QProcess::start(). It should be the path to your executable and further arguments should be added to the QStringlist.

QProcess * process = new QProcess(container);
QString executable("xterm"); // perhaps try "/usr/X11/bin/xterm"
QStringList arguments;
arguments << "-into";
arguments << QString::number(container->winId());
proces->start(executable, arguments);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文