Skip navigation.
Home
The QNX Community Portal

View topic - Why it doesn't work?

Why it doesn't work?

Isn't the name clear?

Why it doesn't work?

Postby xuyong » Thu Aug 07, 2003 3:01 am

I want to change the size of one widget,below is my code:
unsigned short*width,*height;
*width=100;
PtSetResource(widget,Pt_ARG_WIDTH,&width,0);
*height=100;
PtSetResource(widget,Pt_ARG_HEIGHT,&height,0);

but it does't work,why?
xuyong
Senior Member
 
Posts: 431
Joined: Sun Mar 02, 2003 7:52 am

Postby xuyong » Thu Aug 07, 2003 6:07 am

I use another way,
PtArg_t args[2];
args[0].type=Pt_ARG_WIDTH;
args[0].value=(long)100;
args[0].len=0;
args[1].type=Pt_ARG_HEIGHT;
args[1].value=(long)100;
args[1].len=0;
PtSetResources(widget,2,args);
it's ok,but anyone can tell me why the first way can't work?
xuyong
Senior Member
 
Posts: 431
Joined: Sun Mar 02, 2003 7:52 am

Postby cdm » Thu Aug 07, 2003 4:54 pm

That is wrong in so many ways...first, you are dereferencing pointers that don't point to anything. Second, you are passing in a pointer to a pointer to an int when PtSetResource takes an init.

PtSetResource( widget, Pt_ARG_WIDTH, 100, 0 );
PtSetResource( widget, Pt_ARG_HEIGHT, 100, 0);

You only need to use a pointer when are getting the value out.

unsigned short *width;
PtGetResource( widget, Pt_ARG_WIDTH, &width, 0 );
if( width ) {
fprintf( stderr, "width is %d\n", *width );
}

Never modify a resource via the pointer returned though, always copy it and use PtSetResource().
cdm
QNX Master
 
Posts: 789
Joined: Fri Jul 05, 2002 9:38 am


Return to GUI Programming

Who is online

Users browsing this forum: No registered users and 2 guests