Hello Przemek
Thanks fo this excellent code skeleton.
I tried to implement this protocol like this:
hbqt.h
=====
#include <QMainWIndow>
/* global declaration */
typedef void * ( * QT_PARAM_FUNC ) ( int );
typedef struct _QT_PARAM_INFO
{
QT_PARAM_FUNC pFunc;
struct _QT_PARAM_INFO * pNext;
BOOL fInited;
} QT_PARAM_INFO;
extern QMainWindow * hbqt_par_QMainWindow( int iParam );
extern void qt_childregister_QMainWindow( QT_PARAM_INFO * paramInfo );
QWidget * hbqt_par_QWidget( int iParam );
extern void qt_childregister_QWidget( QT_PARAM_INFO * paramInfo );
QWidget.cpp
=========
static HB_GARBAGE_FUNC( release_QWidget )
{
QPointer< QWidget > * pObj =
( QPointer< QWidget > * ) Cargo;
QWidget * obj = * pObj;
if( obj )
{
*pObj = NULL;
delete obj;
}
}
/*----------------------------------------------------------------------*/
static const HB_GC_FUNCS s_gcQWidget =
{
release_QWidget,
hb_gcDummyMark
};
static QT_PARAM_INFO s_paramInfo;
static QT_PARAM_INFO * s_paramList = NULL;
/*----------------------------------------------------------------------*/
/* public function use by descendant classes to register their
* param functions
*/
void qt_childregister_QWidget( QT_PARAM_INFO * paramInfo )
{
if( !paramInfo->fInited )
{
hb_snprintf( str, sizeof( str ), "void qt_childregister_QWidget" );
OutputDebugString( str );
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Executes
/* TODO: add MT protection in fianl version */
paramInfo->fInited = TRUE;
paramInfo->pNext = s_paramList;
s_paramList = paramInfo;
}
}
/*----------------------------------------------------------------------*/
/* public function which extracts pointer to QWidget object
* from given HVM parameter. This parameter may contain also any
* descendant class which register its param function using
* qt_childregister_QWidget().
*/
QWidget * hbqt_par_QWidget( int iParam )
{
QPointer< QWidget > * pObj;
QWidget * obj = NULL;
pObj = ( QPointer< QWidget > * ) hb_parptrGC( &s_gcQWidget, iParam );
if( pObj == NULL )
{
hb_snprintf( str, sizeof( str ), "QWidget * hbqt_par_QWidget() %i", iParam
); OutputDebugString( str );
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Executes fine
/* Not a QWidget pointer item, check all registered
* descendant classes
*/
QT_PARAM_INFO * paramInfo = s_paramList;
while( paramInfo )
{
pObj = ( QPointer< QWidget > * ) paramInfo->pFunc( iParam );
if( pObj )
break;
paramInfo = paramInfo->pNext;
}
}
hb_snprintf( str, sizeof( str ), "QWidget * hbqt_par_QWidget() %i", 2 );
OutputDebugString( str );
^^^^^^^^^^^^^^^^^^^^^^^^^ Executes fine
if( pObj == NULL )
{
hb_snprintf( str, sizeof( str ), "QWidget * hbqt_par_QWidget: pObj == NULL"
); OutputDebugString( str );
^^^^^^^^^^^^^^^^^^^^^ NEVER REACHED - fine
/* RT ERROR - wrong parameter */
}
else
{
obj = ( QWidget * ) * pObj;
if( obj == NULL )
{
hb_snprintf( str, sizeof( str ), "QWidget * hbqt_par_QWidget: obj == NULL"
); OutputDebugString( str );
^^^^^^^^^^^^^^^^^^^^^^^ NEVER Reached - fine
/* RT ERROR - object deleted by other code */
}
}
return obj;
}
/*----------------------------------------------------------------------*/
QPointer< QWidget > * qt_alloc_QWidget( void )
{
QPointer< QWidget > * pObj;
if( !s_paramInfo.fInited )
{
/* First call - register in parent class our param function */
//s_paramInfo.pFunc = ( QT_PARAM_FUNC ) hbqt_par_QObject;
//qt_childregister_QObject( &s_paramInfo );
^^^^^^^^^^^^^^^^^^^^^^^^ Commented out as not implemented yet
/* if class inherits directly from more then one classes
* (multiinheritance) then for each parent class register
* coresponding s_paramInfo<X> parameter
*/
}
pObj = ( QPointer< QWidget > * )
hb_gcAllocate( sizeof( QPointer< QWidget > ),
&s_gcQWidget );
return pObj;
}
/*----------------------------------------------------------------------*/
HB_FUNC( QT_QWIDGET )
{
QPointer< QWidget > * pObj = qt_alloc_QWidget();
*pObj = new QWidget();
hb_retptrGC( pObj );
}
/*----------------------------------------------------------------------*/
HB_FUNC( QT_QWIDGET_SHOW )
{
hb_snprintf( str, sizeof( str ), "HB_FUNC( QT_QWIDGET_SHOW ) 1" );
OutputDebugString( str );
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Executes - fine
QWidget * obj = hbqt_par_QWidget( 1 );
if( obj )
{
hb_snprintf( str, sizeof( str ), "HB_FUNC( QT_QWIDGET_SHOW ) 2 %p", obj
); OutputDebugString( str );
^^^^^^^^^^^^^^^^^^^^^^^^^ Executes - fine obj pointer is visible in debug
window
obj->show(); /////////////// BOOMS GPF
/////////////////////
hb_snprintf( str, sizeof( str ), "HB_FUNC( QT_QWIDGET_SHOW ) 3" );
OutputDebugString( str );
^^^^^^^^^^^^^^^^^^^^^^^^^ NEVER REACHED as GPF's at obj->show()
}
}
/*----------------------------------------------------------------------*/
QMainWindow.cpp
=============
static HB_GARBAGE_FUNC( release_QMainWindow )
{
QPointer< QMainWindow > * pObj =
( QPointer< QMainWindow > * ) Cargo;
QMainWindow * obj = * pObj;
if( obj )
{
*pObj = NULL;
delete obj;
}
}
/*----------------------------------------------------------------------*/
static const HB_GC_FUNCS s_gcQMainWindow =
{
release_QMainWindow,
hb_gcDummyMark
};
static QT_PARAM_INFO s_paramInfo;
static QT_PARAM_INFO * s_paramList = NULL;
/*----------------------------------------------------------------------*/
/* public function use by descendant classes to register their
* param functions
*/
void qt_childregister_QMainWindow( QT_PARAM_INFO * paramInfo )
{
if( !paramInfo->fInited )
{
/* TODO: add MT protection in fianl version */
paramInfo->fInited = TRUE;
paramInfo->pNext = s_paramList;
s_paramList = paramInfo;
}
}
/*----------------------------------------------------------------------*/
/* public function which extracts pointer to QMainWindow object
* from given HVM parameter. This parameter may contain also any
* descendant class which register its param function using
* qt_childregister_QMainWindow().
*/
QMainWindow * hbqt_par_QMainWindow( int iParam )
{
QPointer< QMainWindow > * pObj;
QMainWindow * obj = NULL;
pObj = ( QPointer< QMainWindow > * )
hb_parptrGC( &s_gcQMainWindow, iParam );
if( pObj == NULL )
{
/* Not a QMainWindow pointer item, check all registered
* descendant classes
*/
QT_PARAM_INFO * paramInfo = s_paramList;
while( paramInfo )
{
pObj = ( QPointer< QMainWindow > * )
paramInfo->pFunc( iParam );
if( pObj )
break;
paramInfo = paramInfo->pNext;
}
}
if( pObj == NULL )
{
/* RT ERROR - wrong parameter */
}
else
{
obj = * pObj;
if( obj == NULL )
{
/* RT ERROR - object deleted by other code */
}
}
return obj;
}
/*----------------------------------------------------------------------*/
QPointer< QMainWindow > * qt_alloc_QMainWindow( void )
{
QPointer< QMainWindow > * pObj;
if( !s_paramInfo.fInited )
{
/* First call - register in parent class our param function */
s_paramInfo.pFunc = ( QT_PARAM_FUNC ) hbqt_par_QMainWindow;
qt_childregister_QWidget( &s_paramInfo );
/* if class inherits directly from more then one classes
* (multiinheritance) then for each parent class register
* coresponding s_paramInfo<X> parameter
*/
}
pObj = ( QPointer< QMainWindow > * )
hb_gcAllocate( sizeof( QPointer< QMainWindow > ),
&s_gcQMainWindow );
return pObj;
}
/*----------------------------------------------------------------------*/
HB_FUNC( QT_QMAINWINDOW )
{
QPointer< QMainWindow > * pObj = qt_alloc_QMainWindow();
*pObj = new QMainWindow();
hb_retptrGC( pObj );
}
/*----------------------------------------------------------------------*/
hbqt.prg
======
Local oWnd
oWnd := QMainWindow():new()
oWnd:show() ( called from parent class QWidget )
SYNTHESIS
========
:new method return the correct object.
The whole process goes as intended and touches the
designated functions but GPF's at execution time.
If I implement :show method and corresponding .cpp function,
it executes fine, I can see the window on the screen.
I think there is a small-small error in above implementation. Can you locate
?
Regards
Pritpal Bedi
--
View this message in context:
http://www.nabble.com/HBQT---Nearly-lost-how-to-implement-new-GC-tp26033190p26043426.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