Newbie Question

Hi,

This is my first posting to this News Group. And Forgive me for a long
posting.

I am completely a newbie to QNX. My company is involved in emebeded
software development and is using VxWorks for most of our Developments.
We are designing Set Top Boxes.

I found QNX a real, beuatiful alternative to VxWorks. Most of the
embeded applications require good GUIs and VxWorks has a lousy windowing
support (That to released just a month or two back. It primarily depends
on pJava for GUI) I have introduced QNX in the Office to take a look at
it. And at I am happily using it for few months now.

I was trying my hand at PhAB, and did some elimentary programming.
Pretty impressive. The first comparision which came to my mind was that
of Visual Basic. Well, QNX (or rather PhAB) is Visual Basic for RealTime
(some may scorn). But, if you see, GUI, indeed is a major part of a good
embeded software.

I have got a lot of questions on programming in PhAB. I hope I will get
them cleared in this forum.

I was trying to use PtNumericInteger (?). The code in the
NumericInteger Activate was something like following.


char buffer[20];
int int_val;


PtGetResource(ABW_PtNumericInteger1,Pt_ARG_NUMRIC_INTEGER_VALUE,&int_val,0);

itoa(int_val,buffer,10);
PtSetResource(ABW_PtText1,Pt_ARG_TEXT_STRING,buffer,0);


And I am not getting the value I cange in the NumericInteger. Am I doing
something stupid?


thanks in advance.
Rajeev


Rajeev V,
R&D Engineer
Macmet Interactive Technologies Pvt.Ltd.,
Macmet House,
10B, O.C. Ganguly Sarani,
Calcutta 700 020
INDIA.
Phone Office:
91-33-281-6555 / 281-6557 / 281-6558 / 281-7404 Ext 413.
Fax: 91-33-261 5556
Phone Residence:
91-33-483 2104
Web Site: www.macmetit.com

Previously, Rajeev V wrote in qdn.public.qnxrtp.photon:

I was trying to use PtNumericInteger (?). The code in the
NumericInteger Activate was something like following.


char buffer[20];
int int_val;


PtGetResource(ABW_PtNumericInteger1,Pt_ARG_NUMRIC_INTEGER_VALUE,&int_val,0);

itoa(int_val,buffer,10);
PtSetResource(ABW_PtText1,Pt_ARG_TEXT_STRING,buffer,0);


And I am not getting the value I cange in the NumericInteger. Am I doing
something stupid?

This is certainly not a stupid mistake, but it is a common mistake.
Probably because what you are doing seems like the obvious thing
to do. Try it with this small change:

char buffer[20];
int int_val;
int *pint_val;

PtGetResource(ABW_PtNumericInteger1,Pt_ARG_NUMRIC_INTEGER_VALUE,&pint_val,0);

int_val = *pint_val;

itoa(int_val,buffer,10);
PtSetResource(ABW_PtText1,Pt_ARG_TEXT_STRING,buffer,0);


Mitchell Schoenbrun --------- maschoen@pobox.com

Mitchell Schoenbrun <maschoen@pobox.com> wrote:
: This is certainly not a stupid mistake, but it is a common mistake.
: Probably because what you are doing seems like the obvious thing
: to do. Try it with this small change:

… and take a look at the Manipulating Resources in Application Code chapter
of the Photon Programmer’s Guide.


Steve Reid stever@qnx.com
TechPubs (Technical Publications)
QNX Software Systems

Rajeev V <rajeev@macmetit.com> wrote:

This is my first posting to this News Group. And Forgive me for a long
posting.
[snip]
I was trying to use PtNumericInteger (?). The code in the
NumericInteger Activate was something like following.



char buffer[20];
int int_val;

Here’s your problem. int_val needs to be defined as “int *”, not
“int”. You pass the address of a pointer to the correct type as
the third parameter in PtGetResource, not the address of the type
itself.

PtGetResource(ABW_PtNumericInteger1,Pt_ARG_NUMRIC_INTEGER_VALUE,&int_val,0);

itoa(int_val,buffer,10);
PtSetResource(ABW_PtText1,Pt_ARG_TEXT_STRING,buffer,0);



And I am not getting the value I cange in the NumericInteger. Am I doing
something stupid?

It’s a common problem. :slight_smile:


Here’s a snippet of sample code from our introductory Photon
course. It uses PtGetResources(), not PtGetResource(), and the
resource being retrieved is a string, not a scalar, but the
general principles are the same.


**************** begins ******************************
int my_counter = 100;


int
getNTestCounter( PtWidget_t *widget, ApInfo_t *apinfo,
PtCallbackInfo_t *cbinfo )
{
PtArg_t args[1];
char *new_value_str;
int new_value;

/* Get the new value from the text widget. */
PtSetArg( &args[0], Pt_ARG_TEXT_STRING,
&new_value_str, 0 );
PtGetResources( ABW_pmd_txt_displaycounter, 1, args );

/* Convert the string to an integer. If the conversion
fails, just redisplay the old value of the counter. */
if( sscanf( new_value_str, “%d”, &new_value ) == 1 )
{
my_counter = new_value;
}
displayCounter();

/* eliminate ‘unreferenced’ warnings */
widget = widget, apinfo = apinfo, cbinfo = cbinfo;

return(Pt_CONTINUE);
}


void displayCounter (void)
{
char buf[35];
PtArg_t args[1];

/* Display the current value of the counter. */
itoa( my_counter, buf, 10 );
PtSetArg( &args[0], Pt_ARG_TEXT_STRING, buf, 0 );
PtSetResources( ABW_pmd_txt_displaycounter, 1, args );
}

***************** ends *******************************


I hope this helps.


Norbert Black
QSSL Training Services

to do. Try it with this small change:

char buffer[20];
int int_val;
int *pint_val;


PtGetResource(ABW_PtNumericInteger1,Pt_ARG_NUMRIC_INTEGER_VALUE,&pint_val,0)

;

int_val = *pint_val;

itoa(int_val,buffer,10);
PtSetResource(ABW_PtText1,Pt_ARG_TEXT_STRING,buffer,0);

How about this way? (no extra int required…)

int *pint_val;


PtGetResource(ABW_PtNumericInteger1,Pt_ARG_NUMRIC_INTEGER_VALUE,&pint_val,0)
;
itoa(pint_val[0],buffer,10);
PtSetResource(ABW_PtText1,Pt_ARG_TEXT_STRING,buffer,0);