Skip navigation.
Home
The QNX Community Portal

View topic - Pop Up Dialog Box

Pop Up Dialog Box

Isn't the name clear?

Pop Up Dialog Box

Postby dman3021 » Wed Nov 22, 2006 4:17 pm

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...
dman3021
Active Member
 
Posts: 23
Joined: Thu Feb 16, 2006 8:46 pm

Postby ingraham » Mon Nov 27, 2006 3:31 pm

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.
ingraham
Senior Member
 
Posts: 160
Joined: Wed Nov 05, 2003 2:25 pm
Location: Texas

Postby dman3021 » Thu Nov 30, 2006 4:08 pm

I've modified your solution a little. :D 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! :P

Thanks!

Dan...
dman3021
Active Member
 
Posts: 23
Joined: Thu Feb 16, 2006 8:46 pm

Postby jkohler » Fri Dec 01, 2006 5:19 pm

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.
jkohler
Active Member
 
Posts: 12
Joined: Tue Jun 28, 2005 9:43 pm

Postby dman3021 » Wed Dec 06, 2006 3:31 pm

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
dman3021
Active Member
 
Posts: 23
Joined: Thu Feb 16, 2006 8:46 pm

Postby dman3021 » Wed Dec 06, 2006 7:39 pm

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?
dman3021
Active Member
 
Posts: 23
Joined: Thu Feb 16, 2006 8:46 pm

Postby ingraham » Thu Dec 07, 2006 3:40 pm

"...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.
ingraham
Senior Member
 
Posts: 160
Joined: Wed Nov 05, 2003 2:25 pm
Location: Texas

Postby dman3021 » Mon Dec 11, 2006 8:58 pm

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...
dman3021
Active Member
 
Posts: 23
Joined: Thu Feb 16, 2006 8:46 pm

Postby dman3021 » Wed Apr 18, 2007 6:00 pm

dman3021 wrote:Ok, step two... I want the popup box to beep when it appears.


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...
dman3021
Active Member
 
Posts: 23
Joined: Thu Feb 16, 2006 8:46 pm

Postby mario » Wed Apr 18, 2007 9:23 pm

Tip of the day: puts() is MUCH faster then printf()
mario
QNX Master
 
Posts: 4132
Joined: Sun Sep 01, 2002 1:04 am

Postby maschoen » Wed Apr 18, 2007 9:32 pm

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, ;-).
maschoen
QNX Master
 
Posts: 2640
Joined: Wed Jun 25, 2003 5:18 pm

Postby dman3021 » Thu Apr 19, 2007 2:42 pm

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...
dman3021
Active Member
 
Posts: 23
Joined: Thu Feb 16, 2006 8:46 pm

Postby mario » Thu Apr 19, 2007 3:44 pm

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.
mario
QNX Master
 
Posts: 4132
Joined: Sun Sep 01, 2002 1:04 am


Return to GUI Programming

Who is online

Users browsing this forum: No registered users and 2 guests