views:

660

answers:

1

Hello folks, 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

+1  A: 

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);
Michael Bishop