Some basic questions: creation of buttons 'on the fly' / pro

Hi all.

Here I am again with some basic questions:

— Creating a button. I want to dinamically create a button. In the text of
the button I want to show the value of an integer variable. The fragment of
code is:

<…>
n = 0;
value = 3;
PtSetArg(&args[n++], Pt_ARG_TEXT_STRING, (char )value, 0); / here
the program crashes */
PtCreateWidget(PtButton, window, n, args);
<…>

When I execute this code the program crashes. The problem here is how to
fill the third parameter of the PtSetArg function,
because if I set this parameter with a constant value, for example:

PtSetArg(&args[n++], Pt_ARG_TEXT_STRING, “ButtonText”, 0);

… then it works fine and the button successfully appears. I’ve tried
with (char) and (uchar_t *), with no success.

More problems with the PtSetArg function: In order to set up the top-left
corner of the button I’ve tried the following code:

<…>
PhPoint_t p;

p.x = 20;
p.y = 20;
PtSetArg(&args[n++], Pt_ARG_ORIGIN, p, 0); /* problems! */
<…>

The compiler answers:

…/Obre.cc:73: struct PhPoint_t' used where a long int’ was expected

Any ideas??

— Making the executable. In my project I use a C++ class. In order to
include my files in the project I’ve tried two approaches:

  1. Modifying files ‘indOfiles’, ‘indHfiles’ and ‘indSfiles’ (adding my
    class.o, class.h and class.cc, respectively). Then the make process stops
    with error:

qcc -Vgcc_ntox86 -w5 -O -O3 -fomit-frame-pointer -I. -c -o abmain.o
…/abmain.cc
In file included from …/abmain.cc:37:
proto.h:8: syntax error before ::' <---- Cclass ::Cclass ( void ); proto.h:9: syntax error before ::’ <---- Cclass ::~Cclass
( void );
proto.h:10: syntax error before ::' <---- void Cclass ::method_a int i ); proto.h:11: syntax error before ::’ <---- int Cclass ::method_b
void );
cc: /usr/lib/gcc-lib/ntox86/2.95.2/cc1plus error 33
make[1]: *** [abmain.o] Error 1
make[1]: Leaving directory `/root/provacpp/src/gcc_ntox86’
make: *** [shr] Error 2

As you can see, something’s wrong here with the proto.h generated…

  1. Modifying the files ‘abOfiles’, ‘abHfiles’ and ‘abSfiles’ (adding my
    class.o, class.h and class.cpp, respectively). It works fine, the make
    command compiles my class.cpp and links the executable with my class.o. But
    the problem is that this works UNTIL I generate again the project. After
    that, the reference to my class in the ab*files disappears. I know that
    these files shouldn’t be modified manually, but if approach 1) doesn’t
    work… then I have no choice!! (Do I?)

Any ideas??


TIA

Jordi Garcia

Jordi Garcia <jgbusquets@yahoo.com> wrote:
: Hi all.

: Here I am again with some basic questions:

: — Creating a button. I want to dinamically create a button. In the text of
: the button I want to show the value of an integer variable. The fragment of
: code is:

: <…>
: n = 0;
: value = 3;
: PtSetArg(&args[n++], Pt_ARG_TEXT_STRING, (char )value, 0); / here
: the program crashes */
: PtCreateWidget(PtButton, window, n, args);
: <…>

: When I execute this code the program crashes. The problem here is how to
: fill the third parameter of the PtSetArg function,
: because if I set this parameter with a constant value, for example:

: PtSetArg(&args[n++], Pt_ARG_TEXT_STRING, “ButtonText”, 0);

: … then it works fine and the button successfully appears. I’ve tried
: with (char) and (uchar_t *), with no success.

The value of the resource has to be a string, not a numeric value cast to be
a character. You’re telling the widget to display an unprintable character
whose value is 3 – and you don’t have a \0 to terminate the string.

What you should do is use something like sprintf() to convert the number
into a string, and then pass the string to PtSetArg().

: More problems with the PtSetArg function: In order to set up the top-left
: corner of the button I’ve tried the following code:

: <…>
: PhPoint_t p;

: p.x = 20;
: p.y = 20;
: PtSetArg(&args[n++], Pt_ARG_ORIGIN, p, 0); /* problems! */
: <…>

: The compiler answers:

: …/Obre.cc:73: struct PhPoint_t' used where a long int’ was expected

: Any ideas??

You have to pass the address of the PhPoint_t structure. You should
probably read the Manipulating Resources in Application Code chapter of the
Photon Programmer’s Guide.

: — Making the executable. In my project I use a C++ class. In order to
: include my files in the project I’ve tried two approaches:

: 1) Modifying files ‘indOfiles’, ‘indHfiles’ and ‘indSfiles’ (adding my
: class.o, class.h and class.cc, respectively). Then the make process stops
: with error:

: qcc -Vgcc_ntox86 -w5 -O -O3 -fomit-frame-pointer -I. -c -o abmain.o
: …/abmain.cc
: In file included from …/abmain.cc:37:
: proto.h:8: syntax error before ::' <---- Cclass ::Cclass : ( void ); : proto.h:9: syntax error before ::’ <---- Cclass ::~Cclass
: ( void );
: proto.h:10: syntax error before ::' <---- void Cclass ::method_a : int i ); : proto.h:11: syntax error before ::’ <---- int Cclass ::method_b
: void );
: cc: /usr/lib/gcc-lib/ntox86/2.95.2/cc1plus error 33
: make[1]: *** [abmain.o] Error 1
: make[1]: Leaving directory `/root/provacpp/src/gcc_ntox86’
: make: *** [shr] Error 2

: As you can see, something’s wrong here with the proto.h generated…

: 2) Modifying the files ‘abOfiles’, ‘abHfiles’ and ‘abSfiles’ (adding my
: class.o, class.h and class.cpp, respectively). It works fine, the make
: command compiles my class.cpp and links the executable with my class.o. But
: the problem is that this works UNTIL I generate again the project. After
: that, the reference to my class in the ab*files disappears. I know that
: these files shouldn’t be modified manually, but if approach 1) doesn’t
: work… then I have no choice!! (Do I?)

: Any ideas??

Someone else will have to answer these questions for you.


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

Jordi Garcia <jgbusquets@yahoo.com> wrote:

Hi all.

Here I am again with some basic questions:

— Creating a button. I want to dinamically create a button. In the text of
the button I want to show the value of an integer variable. The fragment of
code is:


n = 0;
value = 3;
PtSetArg(&args[n++], Pt_ARG_TEXT_STRING, (char )value, 0); / here
the program crashes */
PtCreateWidget(PtButton, window, n, args);

Don’t have an answer for your second question (not a c++ programmer), but here’s
one for the first.


char string[20];
int value;

value=3;
sprintf(string,"%d",value);
PtSetArg(&args[n++], Pt_ARG_TEXT_STRING, string, 0);
PtCreateWidget(PtButton, window, n, args);

Problem is that you’re passing the value 3 as the address of a string, instead
of the string “3”.


– drempel

<SNIP C++ stuff>

Hello Jordi,

See below.

Jordi Garcia wrote:

Hi all.

Here I am again with some basic questions:

— Creating a button. I want to dinamically create a button. In the text of
the button I want to show the value of an integer variable. The fragment of
code is:


n = 0;
value = 3;
PtSetArg(&args[n++], Pt_ARG_TEXT_STRING, (char )value, 0); / here
the program crashes */

This is because it is expecting a string and not a intager. What you
can do here is use the itoa() function to convert your value to a string
for use with your Pt_ARG_TEXT_STRING.

PtCreateWidget(PtButton, window, n, args);

When I execute this code the program crashes. The problem here is how to
fill the third parameter of the PtSetArg function,
because if I set this parameter with a constant value, for example:

PtSetArg(&args[n++], Pt_ARG_TEXT_STRING, “ButtonText”, 0);

… then it works fine and the button successfully appears. I’ve tried
with (char) and (uchar_t *), with no success.

More problems with the PtSetArg function: In order to set up the top-left
corner of the button I’ve tried the following code:


PhPoint_t p;

p.x = 20;
p.y = 20;
PtSetArg(&args[n++], Pt_ARG_ORIGIN, p, 0); /* problems! */

The compiler answers:

…/Obre.cc:73: struct PhPoint_t' used where a long int’ was expected

Any ideas??

— Making the executable. In my project I use a C++ class. In order to
include my files in the project I’ve tried two approaches:

  1. Modifying files ‘indOfiles’, ‘indHfiles’ and ‘indSfiles’ (adding my
    class.o, class.h and class.cc, respectively). Then the make process stops
    with error:

qcc -Vgcc_ntox86 -w5 -O -O3 -fomit-frame-pointer -I. -c -o abmain.o
…/abmain.cc
In file included from …/abmain.cc:37:
proto.h:8: syntax error before ::' <---- Cclass ::Cclass ( void ); proto.h:9: syntax error before ::’ <---- Cclass ::~Cclass
( void );
proto.h:10: syntax error before ::' <---- void Cclass ::method_a int i ); proto.h:11: syntax error before ::’ <---- int Cclass ::method_b
void );
cc: /usr/lib/gcc-lib/ntox86/2.95.2/cc1plus error 33
make[1]: *** [abmain.o] Error 1
make[1]: Leaving directory `/root/provacpp/src/gcc_ntox86’
make: *** [shr] Error 2

As you can see, something’s wrong here with the proto.h generated…

  1. Modifying the files ‘abOfiles’, ‘abHfiles’ and ‘abSfiles’ (adding my
    class.o, class.h and class.cpp, respectively). It works fine, the make
    command compiles my class.cpp and links the executable with my class.o. But
    the problem is that this works UNTIL I generate again the project. After
    that, the reference to my class in the ab*files disappears. I know that
    these files shouldn’t be modified manually, but if approach 1) doesn’t
    work… then I have no choice!! (Do I?)

Yes because when you generate again the files are rewritten. This is

why you are not supposed to modify these files. What you want to is
turn of the “Scan source files for prototypes” in the
Application->Startup …" and then declare your prototypes yourself.


Regards
Dave B.



Any ideas??


TIA

Jordi Garcia
\

  1. Modifying the files ‘abOfiles’, ‘abHfiles’ and ‘abSfiles’ (adding my
    class.o, class.h and class.cpp, respectively). It works fine, the make
    command compiles my class.cpp and links the executable with my class.o. But
    the problem is that this works UNTIL I generate again the project. After
    that, the reference to my class in the ab*files disappears. I know that
    these files shouldn’t be modified manually, but if approach 1) doesn’t
    work… then I have no choice!! (Do I?)

You have to add your stuff to indOfiles, indHfiles and indSfiles. Those
are use by phab and not overwriten by it.

Michel Belanger

Steve Reid <stever@qnx.com> escribió en el mensaje de noticias
abolqt$e5m$1@nntp.qnx.com

You have to pass the address of the PhPoint_t structure. You should
probably read the Manipulating Resources in Application Code chapter of
the
Photon Programmer’s Guide.

Hi!

OK. I’ve solved the problem passing the address of the variable:

PtSetArg(&args[n++], Pt_ARG_ORIGIN, &p, sizeof(p));

That’s right, Steve, the solution was explained in the help system. Mea
culpa.

I suppose the solution to the Button text problem is similar to this.


Thanks!

Jordi Garcia.

Applications support <apps@qnx.com> escribió en el mensaje de noticias
3CDFDCA8.5040203@qnx.com

Hello Jordi,

See below.


Yes because when you generate again the files are rewritten. This is
why you are not supposed to modify these files. What you want to is
turn of the “Scan source files for prototypes” in the
Application->Startup …" and then declare your prototypes yourself.

“Scan source files for prototypes” … I’ll investigate this option. :slight_smile:

Thanks!

Jordi Garcia