[comp.windows.x.motif] Need help with Ulowell MotifC++ bindings

apple@nprdc.navy.mil (Jim Apple) (05/17/91)

	I need some help with the Ulowell C++ bindings for Motif.

My problem is that I can not pass a object (XMObject) as a argument
to a function that is in another source file.

	here is a short fragment of what I'm trying to do

----- main.cc
.
void CreateMainMenu( XMForm *  );  
// I've also tried, void CreateMainMenu( XMObject *  );  

void main (unsigned int argc,  char **argv) 
{
  XMApplicationShell topLevel ("topLevel", &argc, argv );
  XMForm mainWindow (&topLevel, "mainWindow" );
  CreateMainMenu( &mainWindow );
}

----- menus.cc

void
CreateMainMenu( XMForm * parent )
{
  XMString string ( "test" );
  XMLabel label ( parent, "label", &string );
  label.Manage();
}

The mainWindow is displayed but I get a message "Destroying Widget ..",
and the  label is never displayed

If I move the three lines from CreateMainMenu to main.cc and replace "parent"
with "&mainWindow", it works fine.

GDB show main.cc:&mainWindow and Menus.cc:parent to be the same address
and type.

Any help would be great

Config:
Sun 3 OS 4.1.1
g++-1.39.1
gdb 3.5


PS: I'd love to hear from anyone else who is using / trying to use
these bindings.  
	Jim Apple 			apple@nprdc.navy.mil
	WB1DOG				...}ucsd!nprdc!apple

kseethar@hawk.ulowell.edu (Krishnan Seetharaman) (05/18/91)

In article <15457@arctic.nprdc.navy.mil> apple@nprdc.navy.mil (Jim Apple) writes:
>
>	I need some help with the Ulowell C++ bindings for Motif.
>
>My problem is that I can not pass a object (XMObject) as a argument
>to a function that is in another source file.
>
>	here is a short fragment of what I'm trying to do
>
>----- main.cc
>.
>void CreateMainMenu( XMForm *  );  
>// I've also tried, void CreateMainMenu( XMObject *  );  
>
>void main (unsigned int argc,  char **argv) 
>{
>  XMApplicationShell topLevel ("topLevel", &argc, argv );
>  XMForm mainWindow (&topLevel, "mainWindow" );
>  CreateMainMenu( &mainWindow );
>}
>
>----- menus.cc
>
>void
>CreateMainMenu( XMForm * parent )
>{
>  XMString string ( "test" );
>  XMLabel label ( parent, "label", &string );
>  label.Manage();
>}
>
>The mainWindow is displayed but I get a message "Destroying Widget ..",
>and the  label is never displayed
>
>If I move the three lines from CreateMainMenu to main.cc and replace "parent"
>with "&mainWindow", it works fine.
>
>GDB show main.cc:&mainWindow and Menus.cc:parent to be the same address

Hi

I tried out the above program and the fix seems to be to put declare the
variables in the other file as static. 

Hope this helps ...

Regards
Krishnan


-- 
K. Seetharaman                         | email : kseethar@cs.ulowell.edu
Graphics Research Laboratory,          | Tel   : 508-934-3612
Department of Computer Science         | 
University of Lowell, Lowell, MA 01854 |

ctim@aaet.csc.ti.com (Craig Timmerman) (05/18/91)

> 	I need some help with the Ulowell C++ bindings for Motif.
> 
> My problem is that I can not pass a object (XMObject) as a argument
> to a function that is in another source file.
> 
> 	here is a short fragment of what I'm trying to do
>
> 
> 
> ----- main.cc
> .
> void CreateMainMenu( XMForm *  );  
> // I've also tried, void CreateMainMenu( XMObject *  );  
> 
> void main (unsigned int argc,  char **argv) 
> {
>   XMApplicationShell topLevel ("topLevel", &argc, argv );
>   XMForm mainWindow (&topLevel, "mainWindow" );
>   CreateMainMenu( &mainWindow );
> }
> 
> ----- menus.cc
> 
> void
> CreateMainMenu( XMForm * parent )
> {
>   XMString string ( "test" );
>   XMLabel label ( parent, "label", &string );
>   label.Manage();
> }
> 
> The mainWindow is displayed but I get a message "Destroying Widget ..",
> and the  label is never displayed

I'm assuming you are using the latest version of the Lowell bindings
(the version that works with Motif 1.1).  In this version I believe
that the destructor for the object calls XtDestroyWidget.  In your
case the label object goes out of scope at the end of CreateMainMenu
and therefore its associated widget will be destroyed before it is
ever displayed.  This would explain the message you see and why it
would work if you move the creation of the label into main--it
wouldn't go out of scope there.  Try explicitly creating the label
using new, and don't delete it.  Your problem should go away.

> PS: I'd love to hear from anyone else who is using / trying to use
> these bindings.  

I have used the first version of the bindings, and may use them again
in the future.
--
----------------------------------------------------------------------
Craig Timmerman 	email: ctim@aaet.csc.ti.com
Texas Instruments	 
Austin, TX		
----------------------------------------------------------------------