why a ptbutton can not be activated while in a loop program?

The ptbutton can be activated when the program ends with PtMainLoop.However,when I defined a loop in the program the ptbutton can not be activated.
Actually,I defined several ptbuttons on one window.when one activated it will receive data from network.when other ptbuttons activated it will stop to do another thing.I tried to write a loop program to determine which ptbutton was activated.But if so,the ptbuttons can not be activated.
I also tried to use callbacks,but if there is a loop program in the callbak function ,other ptbuttons can not be activated.Now I just don’t know how to realize it.
anybody has some idea?thanks!

Not sure exactly what you mean, but if you mean that you cannot press a button while your program is executing a loop, then this is normal. To keep the interface active, you could consider running your loop inside a pthread, or even as a seperate program and use message passing to exchange info between the ‘worker’ program and the UI program.

To be clear,I defined three ptbuttons on one window.One is used to start receiving data from network(once starting,it will receive data looply.So it is a loop subprogram),and the second is used to start another loop subprogram while the third one is used to quit the program.Now I just want to make the UI interactive while running the loop subprogram so that the other two ptbuttons can be activated to stop the running loop and starting another subprogram.

To theqman:You mentioned the pthread.However it seemed that the function RtTrendChangeData() I used now can not be running in pthread. So I defined two global variable rcv_collect and show_demo.When the button rcv activated,set rcv_collect and clear show_demo.When the button showdemo activated ,set show_demo and clear rcv_collect.And in the main function there is a “if” inside a loop to determine to do what,receiving data or demo showing. Unfortunately,when there is a loop in the main function,ptbuttons can not be activated.

Did anybody do something similar before?As I am a green hand of writting program,examples are greatly welcomed.Suggestions are also appreciated!!3X!

You should probably setup an event handler to receive the data. All programs should be event based, that means they wait for something to happen instead of looping to check or wait for the data to come in. Are you using TCP/IP , QNX messaging or some other method.

There is also a section in the manual about handling “lenghtly process” in Photon.

now i am using tcp/ip to receive data from network.can you explain a little more about event handler?ans i am using qnx4.25.thanks.

In helviewer,event handler was defined as a callback function that lets an application respond directly to Photon events.I did difine a callback funciton for the PtButton.And the problem is that how I can realize receiving data from network without stop when the button was activated.

3x!

You must setup a handler that will take care of receving the data. You must not wait for the data in the button callback.
With tcpip you would normal call select() to wait for the data. Obviously you can’t do that in a Photon App in QNX4. Photon does support an select() like call. Look up PtAppAddFd().

Can not find any reference document about PtAppAddFd() in helpviewer…

I have it in helpviewer in qnx425e
Also u can find it here: qnx.com/developers/docs/qnx_ … addfd.html

The help is not part of qnx425 but rather relative to version of Photon. I do know if this was added in what version of Photon. Check /etc/version/phtk.

And how to realize it?I’m new in programming and have no idea at all…Can you give more detail?