PtClearWidget example

The PtClearWidget example program uses the argument “parent” for the first
call of PtCreateWidget(), however, “parent” is never declared or
initialized. What do you specify as a parent if you used PtInit() instead of
PtAppInit() (so no window is created yet)?
Thanks
Markus

Markus Loffler <loffler@ces.clemson.edu> wrote:
: The PtClearWidget example program uses the argument “parent” for the first
: call of PtCreateWidget(), however, “parent” is never declared or
: initialized. What do you specify as a parent if you used PtInit() instead of
: PtAppInit() (so no window is created yet)?

When you create the window, the parent should be NULL:

window = PtCreateWidget( PtWindow, NULL, 1, &argt );

I’ve fixed the example in the docs. Thanks for pointing it out.


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

Steve Reid <stever@qnx.com> wrote:

Markus Loffler <> loffler@ces.clemson.edu> > wrote:
: The PtClearWidget example program uses the argument “parent” for the first
: call of PtCreateWidget(), however, “parent” is never declared or
: initialized. What do you specify as a parent if you used PtInit() instead of
: PtAppInit() (so no window is created yet)?

When you create the window, the parent should be NULL:

window = PtCreateWidget( PtWindow, NULL, 1, &argt );

I’ve fixed the example in the docs. Thanks for pointing it out.

Given that (historically), NULL for this argument has meant “use
the default parent”, wouldn’t it be even better to use the
relatively new Pt_DEFAULT_PARENT instead? Much clearer as to
what’s going on…

Better still (and this is what I tell folks in the advanced
Photon course), use a widget pointer to the container you want as
parent. It only takes a bit of typing, and helps document what
your intentions are to someone who doesn’t know about the default
parenting scheme in Photon.


Norbert Black
QSSL Training Services

You missed my point a little. My main point was that using PtInit(), there
is no parent! If I use PtInit() and then create a widget with parent pointer
0, I get a core dump.

So Steve, modying the example with 0 as the parent won’t do it.

Markus


I’d like to create a window that has the desktop as a parent.
“Norbert Black” <nblack@qnx.com> wrote in message
news:982tdf$7n4$1@nntp.qnx.com

Steve Reid <> stever@qnx.com> > wrote:
Markus Loffler <> loffler@ces.clemson.edu> > wrote:
: The PtClearWidget example program uses the argument “parent” for the
first
: call of PtCreateWidget(), however, “parent” is never declared or
: initialized. What do you specify as a parent if you used PtInit()
instead of
: PtAppInit() (so no window is created yet)?

When you create the window, the parent should be NULL:

window = PtCreateWidget( PtWindow, NULL, 1, &argt );

I’ve fixed the example in the docs. Thanks for pointing it out.

Given that (historically), NULL for this argument has meant “use
the default parent”, wouldn’t it be even better to use the
relatively new Pt_DEFAULT_PARENT instead? Much clearer as to
what’s going on…

Better still (and this is what I tell folks in the advanced
Photon course), use a widget pointer to the container you want as
parent. It only takes a bit of typing, and helps document what
your intentions are to someone who doesn’t know about the default
parenting scheme in Photon.


Norbert Black
QSSL Training Services

Markus Loffler <loffler@ces.clemson.edu> wrote:
: You missed my point a little. My main point was that using PtInit(), there
: is no parent! If I use PtInit() and then create a widget with parent pointer
: 0, I get a core dump.

: So Steve, modying the example with 0 as the parent won’t do it.

Windows are disjoint widgets (i.e. they don’t have to have a parent).
You can specify Pt_NO_PARENT or Pt_DEFAULT_PARENT (which is the same as NULL)
as the parent. It shouldn’t crash (and didn’t for me – I tried all three).

The example shouldn’t have used a variable called “parent” at all. Here’s
the complete, correct version:

#include <Pt.h>

main()
{
PtWidget_t *group, *window;
PtArg_t argt;
PtArg_t argts[3];
PhPoint_t pos ={ 10,10 };

PtInit( NULL );
PtSetArg( &argt, Pt_ARG_POS, &pos, 0 );
window = PtCreateWidget( PtWindow, Pt_NO_PARENT, 1, &argt );

PtSetArg( &argts[0], Pt_ARG_POS, &pos, 0 );
PtSetArg( &argts[1], Pt_ARG_GROUP_ORIENTATION,
Pt_GROUP_VERTICAL, 0 );
group = PtCreateWidget( PtGroup, window, 1, &argt );

PtSetArg( &argt, Pt_ARG_TEXT_STRING, “Button”, 0 );
PtCreateWidget( PtButton, group, 1, &argt );

//using same string as previous button…
PtCreateWidget( PtButton, group, 1, &argt );

PtCreateWidget( PtButton, group, 1, &argt );

PtRealizeWidget( window );

PtContainerHold( group );
PtClearWidget( group );
//destroys all widgets within the group,
//clearing it…

//add new children to the group
PtSetArg( &argt, Pt_ARG_TEXT_STRING,
“New Button”, 0 );
PtRealizeWidget( PtCreateWidget( PtButton, group, 1,
&argt ) );
PtSetArg( &argt, Pt_ARG_TEXT_STRING,
“New Button2”, 0 );
PtRealizeWidget( PtCreateWidget( PtButton, group, 1,
&argt ) );

//force the group to re-align its children and resize.
PtExtentWidget( group );

PtContainerRelease( group );
PtMainLoop();
}


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

Great, it works! Sorry I was wrong, there was something else causing my
crash.
Thanks
Markus

“Steve Reid” <stever@qnx.com> wrote in message
news:98319i$abu$1@nntp.qnx.com

Markus Loffler <> loffler@ces.clemson.edu> > wrote:
: You missed my point a little. My main point was that using PtInit(),
there
: is no parent! If I use PtInit() and then create a widget with parent
pointer
: 0, I get a core dump.

: So Steve, modying the example with 0 as the parent won’t do it.

Windows are disjoint widgets (i.e. they don’t have to have a parent).
You can specify Pt_NO_PARENT or Pt_DEFAULT_PARENT (which is the same as
NULL)
as the parent. It shouldn’t crash (and didn’t for me – I tried all
three).

The example shouldn’t have used a variable called “parent” at all. Here’s
the complete, correct version:

#include <Pt.h

main()
{
PtWidget_t *group, *window;
PtArg_t argt;
PtArg_t argts[3];
PhPoint_t pos ={ 10,10 };

PtInit( NULL );
PtSetArg( &argt, Pt_ARG_POS, &pos, 0 );
window = PtCreateWidget( PtWindow, Pt_NO_PARENT, 1, &argt );

PtSetArg( &argts[0], Pt_ARG_POS, &pos, 0 );
PtSetArg( &argts[1], Pt_ARG_GROUP_ORIENTATION,
Pt_GROUP_VERTICAL, 0 );
group = PtCreateWidget( PtGroup, window, 1, &argt );

PtSetArg( &argt, Pt_ARG_TEXT_STRING, “Button”, 0 );
PtCreateWidget( PtButton, group, 1, &argt );

//using same string as previous button…
PtCreateWidget( PtButton, group, 1, &argt );

PtCreateWidget( PtButton, group, 1, &argt );

PtRealizeWidget( window );

PtContainerHold( group );
PtClearWidget( group );
//destroys all widgets within the group,
//clearing it…

//add new children to the group
PtSetArg( &argt, Pt_ARG_TEXT_STRING,
“New Button”, 0 );
PtRealizeWidget( PtCreateWidget( PtButton, group, 1,
&argt ) );
PtSetArg( &argt, Pt_ARG_TEXT_STRING,
“New Button2”, 0 );
PtRealizeWidget( PtCreateWidget( PtButton, group, 1,
&argt ) );

//force the group to re-align its children and resize.
PtExtentWidget( group );

PtContainerRelease( group );
PtMainLoop();
}


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