[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-devel
Subject: Re: KProcess and KPart
From: Gary Cramblitt <garycramblitt () comcast ! net>
Date: 2003-08-09 1:57:44
[Download RAW message or body]
On Thu, 7 Aug 2003 19:28:09 -0400
Gary Cramblitt <garycramblitt@comcast.net> wrote:
> I need some suggestions for a problem I've having involving KProcess and
> KParts. I've written a KPart that uses KProcess to start a child
> process when user clicks a play button. User can click stop button and
> I call KProcess->kill() to stop the child process. All this is working
> great. Here's the problem. If user clicks play to start the child
> process, then closes my part without clicking stop button, I need to
> call KProcess->kill() to stop the child process. I tried putting
> KProcess->kill() in my part's destructor but this doesn't work. Another
> thread here explained that KProcess has a helper object called
> KProcessController. When my part's destructor is called, KProcessController
> has already been destroyed, so I can't call KProcess->kill().
>
> To work around this problem, I need some way for my kpart to know that
> the part is closing before object destruction begins. So my question
> is: How can a KPart know that it is about to exit? A normal KMainWindow
> gets a queryClose() event, but KParts do not receive this. Whatever
> method I use needs to work whether user clicks File | Close on the menu,
> or clicks back button in Konqueror, or clicks the close button in the
> control box.
Here's a temporary solution I've come up with, but it still would be
better to have a chance to kill the child process BEFORE objects start
getting destroyed. Can anyone help me please?
kspeakPart::~kspeakPart()
{
if (m_process != NULL)
{
// TODO: Bug in KProcess (KDE 3.1-11). When this destructor is called, the
// KProcessController has already been destroyed, therefore, the following
// statement accomplishes nothing.
if (m_process->isRunning())
m_process->kill(SIGTERM);
// We have to terminate the child ourselves and wait for an exit status.
// This solution is less than optimal because it still leaves a kdeinit process
// running.
pid_t pid = m_process->pid();
if (pid)
{
int status;
kill(pid, SIGTERM);
waitpid(pid, &status, 0);
}
// When a KProcess is destroyed, it sends a SIGKILL to the child process.
// In our case, that won't stop speaking, because the signal handler in child process
// won't get a chance to signal the grandchild processes.
delete m_process;
}
}
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic