Pt_ARG_LIST_ITEM_COUNT

Hi there.

I am having problems using Pt_ARG_LIST_ITEM_COUNT to count the number of items in my PtList. Heres my code:

/* Number of items in the item list */
unsigned short  A_count = 0;

/* Ptr for the window (module) that widget is on */
PtWidget_t *PtrWindow = NULL;

/* Ptr to the List_of_Items widget */
PtWidget_t *PtrListItems = NULL;

/* Get Ptr to Window (module) widget is on */
PtrWindow = ApGetInstance( widget );

/* Get pointer to List_of_Items */
PtrListItems = ApGetWidgetPtr(PtrWindow, ABN_List_of_Items);

PtGetResource(PtrListItems, Pt_ARG_LIST_ITEM_COUNT, A_count, 0);

(void)printf("Number of item in list = %d", A_count);

But no matter how many items are in my list i always get the result from Pt_ARG_LIST_ITEM_COUNT being 0 (zero)

Can anyone see what im doing wrong?

Thanks

Try the address of A_count i.e. &A_count in PtGetResource.

No that hasn’t worked. but isn’t that because we are now changing the address of A_count to the result we are getting (zero)??

Any other thoughts?

Got it. You were very close. You do need to do the address of, but also needed to change the variable type to a pointer

unsigned short *A_count = 0;

I guess you assumed I knew that! but i’m still having problems getting to grips with pointers, anyone know any good “idiots guides to pointer”? lol need to read up on this again.

Thanks to thegman.

Just in case anyone else doesn’t quite understand this (but its probably just me!), what I now realise is that the function PtGetResource doesn’t return the actual value, it returns the address of the location of the value. This mean that you just need to create a pointer to store that address in.

I have also found that QNX say not to change these values directly using the point, but to make a copy of the value, make your changes to that value, then use the PtSetResource(s) function to apply the change.

Hope this helps someone else.

To help prevent change to the value, the pointer should be of type const