Skip navigation.
Home
The QNX Community Portal

View topic - how to connect PtGetResource with a button?

how to connect PtGetResource with a button?

Isn't the name clear?

how to connect PtGetResource with a button?

Postby bzxaggio » Mon Nov 08, 2010 8:41 am

I would like to input a number using PtText widget, and press a PtButton to assign this number to a variable which contains in code. The question is, do I have to add any callback between PtText and PtButton? And also how to use PtGetResource to assign the value to a variable? Thank you guys.
bzxaggio
Active Member
 
Posts: 16
Joined: Tue Aug 24, 2010 10:09 pm
Location: CHI

RE: how to connect PtGetResource with a button?

Postby maschoen » Mon Nov 08, 2010 6:10 pm

If you don't put in any code, when you press the button, nothing happens. You need to use PhAB to put in an "Activate" callback on the button. In the callback you read the text widget's data and puts it's value into the variable.

An alternative is to use the Numeric-Integer widget. You don't need a callback, but instead you would get this widget's value whenever you want to use the variable. You could however put in a "Changed" callback if you want to know when the variable is changed.


PtGetResource is well documented in the online docs. It's complicated because it handles different types of widget resources. The best docs are for PtGetResources(). The tricky part is that usually you send the address of a pointer variable. That's two levels of indirection. The routine takes the address (a pointer) and fills in a pointer value, which you use to point at your data.
maschoen
QNX Master
 
Posts: 2644
Joined: Wed Jun 25, 2003 5:18 pm

Re: RE: how to connect PtGetResource with a button?

Postby bzxaggio » Fri Nov 12, 2010 4:55 pm

maschoen wrote:If you don't put in any code, when you press the button, nothing happens. You need to use PhAB to put in an "Activate" callback on the button. In the callback you read the text widget's data and puts it's value into the variable.

An alternative is to use the Numeric-Integer widget. You don't need a callback, but instead you would get this widget's value whenever you want to use the variable. You could however put in a "Changed" callback if you want to know when the variable is changed.


PtGetResource is well documented in the online docs. It's complicated because it handles different types of widget resources. The best docs are for PtGetResources(). The tricky part is that usually you send the address of a pointer variable. That's two levels of indirection. The routine takes the address (a pointer) and fills in a pointer value, which you use to point at your data.



For example:if a text string widget is "datatext1", and I would like to get its text string after press a button, I just add a code callback to this button, and in code write like this:

PtWidget_t *datatext1;
char *flags;
PtGetResource(datatext1, Pt_ARG_TEXT_STRING, &flags, 0);

so the text string in text widget just set to the flags? But I cannot compile it well, so any suggestions? Thank you.
bzxaggio
Active Member
 
Posts: 16
Joined: Tue Aug 24, 2010 10:09 pm
Location: CHI

RE: Re: RE: how to connect PtGetResource with a button?

Postby mario » Fri Nov 12, 2010 5:01 pm

Could you indicate the error you get. The code you posted looks ok to me.
mario
QNX Master
 
Posts: 4132
Joined: Sun Sep 01, 2002 1:04 am

RE: Re: RE: how to connect PtGetResource with a button?

Postby maschoen » Fri Nov 12, 2010 6:24 pm

Yes, what does "cannot compile it" mean?
maschoen
QNX Master
 
Posts: 2644
Joined: Wed Jun 25, 2003 5:18 pm

Re: RE: Re: RE: how to connect PtGetResource with a button?

Postby bzxaggio » Fri Nov 12, 2010 10:01 pm

mario wrote:Could you indicate the error you get. The code you posted looks ok to me.




Compile is good, and can run under PhAB.but when I type something in the PtText, then press the button, the whole program will close immediately, maybe add the wrong callback between code and widget, plz give me some suggestions.

In my code, "datatext_1" is the instance name of PtText and "flags" is the pointer to storage the name of txt file.
bzxaggio
Active Member
 
Posts: 16
Joined: Tue Aug 24, 2010 10:09 pm
Location: CHI

Re: RE: Re: RE: how to connect PtGetResource with a button?

Postby bzxaggio » Fri Nov 12, 2010 10:02 pm

maschoen wrote:Yes, what does "cannot compile it" mean?



Compile is good, and can run under PhAB.But when I type something in the PtText, then press the button, the whole program will close immediately, maybe add the wrong callback between code and widget, plz give me some suggestions!

In my code, "datatext_1" is the instance name of PtText and "flags" is the pointer to storage the name of txt file.
bzxaggio
Active Member
 
Posts: 16
Joined: Tue Aug 24, 2010 10:09 pm
Location: CHI

RE: Re: RE: Re: RE: how to connect PtGetResource with a butt

Postby maschoen » Mon Nov 15, 2010 7:20 pm

I suggest you post your code.
maschoen
QNX Master
 
Posts: 2644
Joined: Wed Jun 25, 2003 5:18 pm

Re: RE: Re: RE: Re: RE: how to connect PtGetResource with a

Postby bzxaggio » Tue Nov 16, 2010 8:21 pm

maschoen wrote:I suggest you post your code.


Yech got it, like this
PtGetResource(ABW_data_file1, Pt_ARG_TEXT_STRING, &data_1, 0);

I dont know why but should add ABW before widget instance name.
bzxaggio
Active Member
 
Posts: 16
Joined: Tue Aug 24, 2010 10:09 pm
Location: CHI

RE: Re: RE: Re: RE: Re: RE: how to connect PtGetResource wit

Postby maschoen » Tue Nov 16, 2010 9:18 pm

If you look in the src director you will find .h files generated by PhAB. Each widget with an instance name generates a value ABW_xxxx.
maschoen
QNX Master
 
Posts: 2644
Joined: Wed Jun 25, 2003 5:18 pm


Return to GUI Programming

Who is online

Users browsing this forum: No registered users and 3 guests