Hello Viktor

Viktor Szakáts wrote:
> 
> In order to let GC collect these pointer automatically
> you need to use hb_retptrGC(), along with a callback
> to the freeing.
> 

So, I tried like this:


static HB_GARBAGE_FUNC( QMessageBox_release )
{
   void ** ph = ( void ** ) Cargo;

   /* Check if pointer is not NULL to avoid multiple freeing */
   if( ph && * ph )
   {
      /* Destroy the object */
      delete ( ( QMessageBox * ) ph );

      /* set pointer to NULL to avoid multiple freeing */
      * ph = NULL;
   }
}

static QMessageBox* xhbqt_par_QMessageBox( int iParam )
{
   void ** ph = ( void ** ) hb_parptrGC( QMessageBox_release, iParam );

   return ph ? ( QMessageBox * ) ph : NULL;
}

HB_FUNC( QT_QMESSAGEBOX )
{
   void ** ph = ( void ** ) hb_gcAlloc( sizeof( QMessageBox ),
QMessageBox_release );

   * ph = new QMessageBox();

   hb_retptrGC( ( QMessageBox * ) ph );
}

/*
 * DESTRUCTOR
 */
HB_FUNC( QT_QMESSAGEBOX_DESTROY )
{
   void ** ph = ( void ** ) hb_parptrGC( QMessageBox_release, 1 );

   if( ph && * ph )
   {
      delete ( ( QMessageBox * ) ph );
      * ph = NULL;
   }
}

HB_FUNC( QT_QMESSAGEBOX_SETINFORMATIVETEXT )
{
   xhbqt_par_QMessageBox( 1 )->setInformativeText( hbqt_par_QString( 2 ) );
}

The code compiles fine but produces GPF as

   oMB :=  QMessageBox():new()
   ^^^^^^^^^^^^^^^^^^^     OK
   oMB:setInformativeText( "PushButton" ) 
   ^^^^^^^^^^^^^^^^^^^^^^^^     GPF

I mean any next call produces this.
What I am doing wrong?

Regards
Pritpal Bedi
   
-- 
View this message in context: 
http://www.nabble.com/HBQT---HBXBP-%3A-Garbage-Collection-tp25813841p25816231.html
Sent from the Harbour - Dev mailing list archive at Nabble.com.

_______________________________________________
Harbour mailing list
[email protected]
http://lists.harbour-project.org/mailman/listinfo/harbour

Reply via email to