From 5e2f9f9a96fd249ffb34b5a91108ccac066fae44 Mon Sep 17 00:00:00 2001 From: Pritpal Bedi Date: Tue, 22 Mar 2011 22:13:36 +0000 Subject: [PATCH] 2011-03-22 15:05 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) * contrib/hbqt/qtcore/hbqt_hbqevents.cpp * contrib/hbqt/qtcore/hbqt_hbqslots.cpp ! Changed: the behaviour of oQObject:connect(). Now if called next time, it will replace the original codeblock. This is important in certain situations. ! Fixed: potential memory leak. * contrib/hbqt/qtcore/hbqt_misc.prg ! Introduced: DESTRUCTOR _destroy() which explictly destroys singals and slots prior to destroying the object. [ Francessco ]. This renderes calling oQObject:disconnect() useless. Now there is no more GPF on hbIDE. Please build for different OS's and report on the list. ; TODO: remove :disconnect calls from hbXBP and hbIDE. --- harbour/ChangeLog | 29 ++++++++++++++ .../contrib/hbqt/qtcore/hbqt_hbqevents.cpp | 38 ++++++++++++------- harbour/contrib/hbqt/qtcore/hbqt_hbqslots.cpp | 22 +++++++++-- harbour/contrib/hbqt/qtcore/hbqt_misc.prg | 24 ++++++++++-- 4 files changed, 93 insertions(+), 20 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 3e937591d2..7de3b95f57 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,35 @@ The license applies to all entries newer than 2009-04-28. */ +2011-03-22 15:05 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) + * contrib/hbqt/qtcore/hbqt_hbqevents.cpp + * contrib/hbqt/qtcore/hbqt_hbqslots.cpp + ! Changed: the behaviour of oQObject:connect(). + Now if called next time, it will replace the original codeblock. + This is important in certain situations. + ! Fixed: potential memory leak. + + * contrib/hbqt/qtcore/hbqt_misc.prg + ! Introduced: DESTRUCTOR _destroy() which explictly destroys + singals and slots prior to destroying the object. [ Francessco ]. + This renderes calling oQObject:disconnect() useless. + Now there is no more GPF on hbIDE. Please build for + different OS's and report on the list. + + ; TODO: remove :disconnect calls from hbXBP and hbIDE. + +2011-03-21 18:45 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) + * contrib/hbqt/qtcore/hbqt_init.cpp + * contrib/hbqt/qtgui/hbqt_init.cpp + ! Transferred logic of destructors from core to gui. + The whole lot should be in one source. We cannot + control the order of execution of _init_ functions. + Francessco, take care of these changes. + + NOTE: now hbIDE enters, used with all flavours, exits + without GPF. The remaining issue is to control + memory leaks. Francessco is working onto that. + 2011-03-21 18:36 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) * contrib/hbide/idebrowse.prg * contrib/hbide/idedocks.prg diff --git a/harbour/contrib/hbqt/qtcore/hbqt_hbqevents.cpp b/harbour/contrib/hbqt/qtcore/hbqt_hbqevents.cpp index 2fc5da17bf..f45a5a1a9a 100644 --- a/harbour/contrib/hbqt/qtcore/hbqt_hbqevents.cpp +++ b/harbour/contrib/hbqt/qtcore/hbqt_hbqevents.cpp @@ -248,21 +248,33 @@ HB_FUNC( __HBQT_EVENTS_CONNECT ) if( object ) { - int type = hb_parni( 3 ); - - char prop[ 20 ]; - hb_snprintf( prop, sizeof( prop ), "P%iP", type ); /* Make it a unique identifier */ - - int i = object->property( prop ).toInt(); - if( i == 0 ) /* No Duplicates of same event with same object - it is a design decision - never alter */ + PHB_ITEM codeblock = hb_itemNew( hb_param( 4, HB_IT_BLOCK | HB_IT_BYREF ) ); + if( codeblock ) { - PHB_ITEM codeblock = hb_itemNew( hb_param( 4, HB_IT_BLOCK | HB_IT_BYREF ) ); + int type = hb_parni( 3 ); - t_events->listBlock << codeblock; + char prop[ 20 ]; + hb_snprintf( prop, sizeof( prop ), "P%iP", type ); /* Make it a unique identifier */ - object->setProperty( prop, ( int ) t_events->listBlock.size() ); + int i = object->property( prop ).toInt(); + if( i == 0 ) /* No Duplicates of same event with same object - it is a design decision - never alter */ + { + t_events->listBlock << codeblock; - nResult = 0; + object->setProperty( prop, ( int ) t_events->listBlock.size() ); + + nResult = 0; + } + else + { + if( t_events->listBlock.at( i - 1 ) != NULL ) + { + hb_itemRelease( t_events->listBlock.at( i - 1 ) ); + } + t_events->listBlock[ i - 1 ] = codeblock; + + nResult = 0; + } } else nResult = -3; @@ -299,10 +311,10 @@ HB_FUNC( __HBQT_EVENTS_DISCONNECT ) if( t_events->listBlock[ i - 1 ] != NULL ) { - HB_TRACE( HB_TR_ALWAYS, ( " __HBQT_EVENTS_DISCONNECT %d=", i-1 ) ); + HB_TRACE( HB_TR_DEBUG, ( " __HBQT_EVENTS_DISCONNECT %d=", i-1 ) ); hb_itemRelease( t_events->listBlock.at( i - 1 ) ); t_events->listBlock[ i - 1 ] = NULL; - HB_TRACE( HB_TR_ALWAYS, ( " X=" ) ); + HB_TRACE( HB_TR_DEBUG, ( " X=" ) ); } nResult = 0; diff --git a/harbour/contrib/hbqt/qtcore/hbqt_hbqslots.cpp b/harbour/contrib/hbqt/qtcore/hbqt_hbqslots.cpp index 5742e0e42b..ba1f6443dc 100644 --- a/harbour/contrib/hbqt/qtcore/hbqt_hbqslots.cpp +++ b/harbour/contrib/hbqt/qtcore/hbqt_hbqslots.cpp @@ -216,7 +216,7 @@ int HBQSlots::qt_metacall( QMetaObject::Call c, int id, void ** arguments ) */ HB_FUNC( __HBQT_SLOTS_CONNECT ) { - int nResult; + int nResult = 0; HBQSlots * t_slots = hbqt_par_HBQSlots( 1 ); if( t_slots ) @@ -224,7 +224,7 @@ HB_FUNC( __HBQT_SLOTS_CONNECT ) QObject * object = ( QObject * ) hbqt_pPtrFromObj( 2 ); /* get sender */ if( object ) { - PHB_ITEM pBlock = hb_itemNew( hb_param( 4, HB_IT_BLOCK ) ); /* get codeblock */ + PHB_ITEM pBlock = hb_itemNew( hb_param( 4, HB_IT_BLOCK | HB_IT_BYREF ) ); /* get codeblock */ if( pBlock ) { const char * pszSignal = hb_parcx( 3 ); @@ -268,10 +268,24 @@ HB_FUNC( __HBQT_SLOTS_CONNECT ) nResult = 5; } else - nResult = 4; + { + if( t_slots->listBlock.at( i - 1 ) != NULL ) + { + hb_itemRelease( t_slots->listBlock.at( i - 1 ) ); + } + t_slots->listBlock[ i - 1 ] = pBlock; + nResult = 0; + } + + if( nResult > 0 ) + { + hb_itemRelease( pBlock ); + } } else + { nResult = 3; + } } else nResult = 2; @@ -285,6 +299,7 @@ HB_FUNC( __HBQT_SLOTS_CONNECT ) /* * Harbour function to disconnect signals */ + HB_FUNC( __HBQT_SLOTS_DISCONNECT ) { int nResult; @@ -318,6 +333,7 @@ HB_FUNC( __HBQT_SLOTS_DISCONNECT ) if( t_slots->listBlock.at( i - 1 ) != NULL ) { + HB_TRACE( HB_TR_ALWAYS, ( " __HBQT_SLOTS_DISCONNECT %d", i ) ); hb_itemRelease( t_slots->listBlock.at( i - 1 ) ); t_slots->listBlock[ i - 1 ] = NULL; } diff --git a/harbour/contrib/hbqt/qtcore/hbqt_misc.prg b/harbour/contrib/hbqt/qtcore/hbqt_misc.prg index 2d6675be58..0a831ba3ee 100644 --- a/harbour/contrib/hbqt/qtcore/hbqt_misc.prg +++ b/harbour/contrib/hbqt/qtcore/hbqt_misc.prg @@ -52,6 +52,7 @@ #include "hbclass.ch" #include "error.ch" +#include "hbtrace.ch" /*----------------------------------------------------------------------*/ @@ -59,14 +60,15 @@ CREATE CLASS HbQtObjectHandler VAR pPtr /* TODO: Rename to __pPtr */ - VAR __pSlots PROTECTED - VAR __pEvents PROTECTED + VAR __pSlots PROTECTED + VAR __pEvents PROTECTED METHOD fromPointer( pPtr ) METHOD hasValidPointer() METHOD connect( cnEvent, bBlock ) METHOD disconnect( cnEvent ) + DESTRUCTOR _destroy() ERROR HANDLER onError() @@ -177,8 +179,8 @@ METHOD HbQtObjectHandler:connect( cnEvent, bBlock ) /*----------------------------------------------------------------------*/ METHOD HbQtObjectHandler:disconnect( cnEvent ) + #if 0 LOCAL nResult - SWITCH ValType( cnEvent ) CASE "C" @@ -212,8 +214,22 @@ METHOD HbQtObjectHandler:disconnect( cnEvent ) ENDSWITCH __hbqt_error( 1300 + nResult ) - RETURN .F. + #endif + RETURN cnEvent + +/*----------------------------------------------------------------------*/ + +METHOD HbQtObjectHandler:_destroy() + + HB_TRACE( HB_TR_DEBUG, " _destroy()", ::className(), 0 ) + + ::__pSlots := NIL + ::__pEvents := NIL + + HB_TRACE( HB_TR_DEBUG, " _destroy()", ::className(), 1 ) + + RETURN NIL /*----------------------------------------------------------------------*/