You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Wednesday, April 29th 2009, 7:04am

QPushButton send click signal mutliple times

Hi all.
When user click the button, I need to start another process with QProcess.
I connect those handler function to "click" signal of the button.
The problem is that, the process start need some times like 10 seconds. Before the process
show, I just want user to wait, and if user click button during the waiting, the click should be neglected.
persuade code is like

Quoted


handler ()
{
if (isProcessing)
return
isProcessing = true;
process ();//need 10 sec here to start the new process
isProcessing = false;
}

But it seems that the Qt will queue the following click request. So if the user click button 3 times,
there will be 3 process start. How to neglect the last 2 click event.

Thanks

2

Wednesday, April 29th 2009, 4:47pm

You cannot do like this.
When you start your process, you return immediately to your Qt application and it continues to run. That is why isprocessing if true then immediately becomes false. So the following clics will also launch the process. What you need to do is to synchronize the two processes. By exanching messages for example :

When the launched process has started, you "signal" it to the parent process by sending a message (via tcp/ip for instance). I think that Qt signals will not work across processes, and may not work even across threads. If you cant to use a signal/slot mechanism, you'll need a cross-process signalling mechanism, for exemple libsigc++.

Anyway the best way to do what you want is to exchange some message. Example, you may create a file that when it is deleted lets the parent process know that the process has started.