Hi Przemek

Przemyslaw Czerpak-2 wrote:
> 
> Here is mistake. The last line should be changed to:
>    return ph ? ( QMessageBox * ) * ph : NULL;
> 

Yep. And now GC pointers are working as expected.

BUT I have run into another trouble.
HBQT implements this prg level class 

CREATE CLASS QWidget INHERIT QObject, QPaintDevice
   VAR     pPtr
   METHOD  New()
   METHOD  setWindowTitle( cTitle )            INLINE 
Qt_QWidget_setWindowTitle( ::pPtr, cTitle )

   ENDCLASS



CREATE CLASS QMainWindow INHERIT QWidget
   VAR     pPtr
   METHOD  New()
 
   ENDCLASS


PRG Code:

   oWnd := QMainWindow():new()
   oWnd:setWindowTitle( "My First Window" )

Without GC pointers methods called from parent class were
being executed properly as in corresponding .cpp pointers were being 
typecasted to its native class no matter from where they were being 
supplied.

Now with GC implementation I could not achieve dynamic casting 
and so the appln generates GPF when a method is called from parent 
class. Current .cpp code looks like this:

QWidget.cpp
=========

static HB_GARBAGE_FUNC( QWidget_release )
{
   void ** ph = ( void ** ) Cargo;
   if( ph && * ph )
   {
      delete ( ( QWidget * ) * ph );
      * ph = NULL;
   }
}

static QWidget * qt_par_QWidget( int iParam )
{
   void ** ph = ( void ** ) hb_parptrGC( QWidget_release, iParam );
   return ph ? ( QWidget * ) * ph : NULL;
}

HB_FUNC( QT_QWIDGET )
{
   void ** ph = ( void ** ) hb_gcAlloc( sizeof( QObject ), Q_Object_release
);

   * ph = new QWidget( hbqt_par_QWidget( 1 ), ( Qt::WindowFlags ) hb_parni(
2 ) ) ;

   hb_retptrGC( ph );
}

HB_FUNC( QT_QWIDGET_SETWINDOWTITLE )
{
   qt_par_QWidget( 1 )->setWindowTitle( hbqt_par_QString( 2 ) );
}

QMainWindow.cpp
=============

static HB_GARBAGE_FUNC( QMainWindow_release )
{
   void ** ph = ( void ** ) Cargo;
   if( ph && * ph )
   {
      delete ( ( QMainWindow * ) * ph );
      * ph = NULL;
   }
}

static QMainWindow * qt_par_QMainWindow( int iParam )
{
   void ** ph = ( void ** ) hb_parptrGC( QMainWindow_release, iParam );
   return ph ? ( QMainWindow * ) * ph : NULL;
}

HB_FUNC( QT_QMAINWINDOW )
{
   void ** ph = ( void ** ) hb_gcAlloc( sizeof( QMainWindow ),
QMainWindow_release );

   * ph = new QMainWindow( hbqt_par_QWidget( 1 ), ( Qt::WindowFlags )
hb_parni( 2 ) ) ;

   hb_retptrGC( ph );
}

HB_FUNC( QT_QMAINWINDOW_SETANIMATED )
{
   qt_par_QMainWindow( 1 )->setAnimated( hb_parl( 2 ) );
}

Before   qt_par_QMainWindow()  was defined as 
   #define qt_par_QMainWindow( n )     ( ( QMainWindow * ) hb_parptr( n ) )

and qt_par_QWidget() was defined as 
   #define qt_par_QWidget( n )     ( ( QWidget * ) hb_parptr( n ) )

And as the calls were made to parent objects with the sam pointer 
created in child class and then in parent those were typecasted to 
its native object and hence call was carried out properly.

Under current scenario qt_par_QMainWindow() and qt_par_QWidget()
are static functions returning the current specific object the previous
functionality is no more applicable. There may be a way to define 
GC pointers dynamically and we may have some mechanism to typecast 
them dynamically, but at least I do not know how to.

Can you guide us to this direction?

Regards
Pritpal Bedi

PS: It may be highly possible that I could not explain the problem properly,
      so please bear with me.

-- 
View this message in context: 
http://www.nabble.com/HBQT---HBXBP-%3A-Garbage-Collection-tp25813841p25835783.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