Pop Up Dialog Box

I was wondering if there is an easy way of creating a PopUp Dialog Box in a QNX Project using PhAB.

What I need is a PopUp Dialog to appear on screen when a certain event or alarm is raised in my program.

I figure I can build the whole thing from code and dynamically generate the dialog box, but I was wondering if there is an option in PhAB for this kind of action.

Thanks,

Dan…

Sure… sorta. The dialog itself can be generated in PhAB. The event itself is a little trickier, but basically drop a timer on your base window and check for the event in the timer’s activate callback. When the event happens call ApCreateModule(). In PhAB, make sure you create a link (Project → Internal Links) to define the location & setup function.

To summarize:
In PhAB, create dialog and it’s internal link, and create a timer on the base window.

In code, watch for the event in the timer callback and call ApCreateModule().

That’s it.

-James Ingraham
Sage Automation, Inc.

I’ve modified your solution a little. :smiley: Instead of having a timer cicle every x seconds, I’ve setup signal handlers that receive signals when a pop-up is required. Signal hanlders work great, but I’m crashing when I call ApCreateModule (ABM_Stuff, NULL, NULL). It sucks because the debugger doesn’t seem to be able to step through the signal handler.

Ah well, can’t have all I want I guess. I’ll keep on working on this signal stuff, but if I start running around in circles, I may just use a timer afterall! :stuck_out_tongue:

Thanks!

Dan…

When you say ‘signal handler’ are you using PtAppAddSignalProc() or a raw signal handler (i.e. signal() and friends)?

Calling into the photon libraries from within a raw signal handler would not work - use PtAppAddSignalProc to get photon/phab friendly handlers.

I’ve been using signal() for a while, and everything was working fine, until I attempted to call ApCreateModule using my raw signal handler.

I’ve set the whole thing up with a timer, but didnt know about PtAppAddSignalProc()… I’ll check it out.

Thanks

Ok, step two… I want the popup box to beep when it appears. Should be simple, yes?

I basically added printf("\a"); before I call ApCreateModule(), but no sound… So I figure I did something wrong, and when I close the application I hear a beep.

So I try different things, moving the printf around, adding another, adding text after \a… nothing seems to get the system to beep until I shut down the app.

Any ideas?

“…nothing seems to get the system to beep until I shut down the app.”

You’re not going to believe me, but this code should work:

printf("\a\n");

Alternately:

printf("\a");
fflush(stdout);

-James Ingraham
Sage Automation, Inc.

Hehe,

yea, a coworker explained that prinf wont print until it hits a \n or is full.

I guess this is part of those embarrassing little things that you learn while doing…

Thanks,

Dan…

Well, turns out the /a works fine, as long as a terminal window is open. If I close the terminal window I’ve started the app in, I no longer hear beeps.

So now I figure I might want to play a wave file instead of just a simple beep, and was wondering if anyone knew if there is an easy way to do so?

Thanks,

Dan…

Tip of the day: puts() is MUCH faster then printf()

It’s not printf that is the problem, but rather the behavior of stdout.
A friendly snipe at Mario: Do you think you will hear the beep faster if you send the “\a\n” via puts rather than printf, ;-).

fp = fopen( “/dev/con1”, “w” );
if( fp != NULL ) {
putc(’\a’, fp);
putc(’\n’, fp);
fclose( fp );
}

So basically opening a stream to con1 and printing the beep character there works (as I’ve done with the above code).

Thanks for the push!

Dan…

In that case you don’t need the putc() because fclose will flush it for you.

Hey Mitch, lol! I jumped on the occasion to mention puts, because I recently wrote some benchmark program to evaluate performance of printf, sprintf, puts and their C++ counter part cout, strstream stringstream.

I was amazed to see that puts was almost 10 times faster then printf. That’s understandable because puts doesn’t have to parse the string to look for format (%…).

I was also surprised to see that cout was also faster the printf ( almost as fast a puts ) and for the same reason; no parsing. It however makes the code bigger, each value use in the cout expression results in a call.

strstream, stringstream also proved much faster then sprintf even if they perform memory allocation.