From d9735d4b8794041f265ad0e8a48b9f02027e27f2 Mon Sep 17 00:00:00 2001 From: Pritpal Bedi Date: Sun, 20 Mar 2011 06:25:52 +0000 Subject: [PATCH] 2011-03-19 23:21 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) * contrib/hbqt/hbmk2_qt.hbs * contrib/hbqt/qtcore/hbqt.h * contrib/hbqt/qtcore/hbqt_hbqevents.cpp * contrib/hbqt/qtcore/hbqt_hbqslots.cpp * contrib/hbqt/qtcore/hbqt_init.cpp * contrib/hbqt/qtcore/hbqt_pointer.cpp ! Applied: Francessco's patch with few changes and formatting. * contrib/hbqt/qtgui/hbqt_hbqtableview.cpp ! hbqt_create_object() => hbqt_create_objectGC() * contrib/hbqt/qtgui/THbQtUI.prg ! Rationalized: object destruction. * contrib/hbqt/tests/demoqt.prg ! Rationalized. --- harbour/ChangeLog | 18 ++++++ harbour/contrib/hbqt/hbmk2_qt.hbs | 4 +- harbour/contrib/hbqt/qtcore/hbqt.h | 1 + .../contrib/hbqt/qtcore/hbqt_hbqevents.cpp | 57 ++++++++++++++++--- harbour/contrib/hbqt/qtcore/hbqt_hbqslots.cpp | 3 +- harbour/contrib/hbqt/qtcore/hbqt_init.cpp | 18 ++++++ harbour/contrib/hbqt/qtcore/hbqt_pointer.cpp | 15 ++--- harbour/contrib/hbqt/qtgui/THbQtUI.prg | 7 +++ .../contrib/hbqt/qtgui/hbqt_hbqtableview.cpp | 12 +++- harbour/contrib/hbqt/tests/demoqt.prg | 28 +++------ 10 files changed, 121 insertions(+), 42 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index f23aa96d54..d908f4556d 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,24 @@ The license applies to all entries newer than 2009-04-28. */ +2011-03-19 23:21 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) + * contrib/hbqt/hbmk2_qt.hbs + * contrib/hbqt/qtcore/hbqt.h + * contrib/hbqt/qtcore/hbqt_hbqevents.cpp + * contrib/hbqt/qtcore/hbqt_hbqslots.cpp + * contrib/hbqt/qtcore/hbqt_init.cpp + * contrib/hbqt/qtcore/hbqt_pointer.cpp + ! Applied: Francessco's patch with few changes and formatting. + + * contrib/hbqt/qtgui/hbqt_hbqtableview.cpp + ! hbqt_create_object() => hbqt_create_objectGC() + + * contrib/hbqt/qtgui/THbQtUI.prg + ! Rationalized: object destruction. + + * contrib/hbqt/tests/demoqt.prg + ! Rationalized. + 2011-03-18 23:06 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) * contrib/hbqt/qtcore/hbqt_hbqevents.cpp * contrib/hbqt/qtcore/hbqt_hbqslots.cpp diff --git a/harbour/contrib/hbqt/hbmk2_qt.hbs b/harbour/contrib/hbqt/hbmk2_qt.hbs index 2a67c9b11a..58c727ae7e 100644 --- a/harbour/contrib/hbqt/hbmk2_qt.hbs +++ b/harbour/contrib/hbqt/hbmk2_qt.hbs @@ -705,8 +705,9 @@ STATIC FUNCTION hbqtui_gen_prg( cFile, cFuncName ) AAdd( aLinesPRG, " LOCAL hWidget := { => }" ) AAdd( aLinesPRG, "" ) AAdd( aLinesPRG, " hb_hCaseMatch( hWidget, .F. )" ) + AAdd( aLinesPRG, " hb_hKeepOrder( hWidget, .T. )" ) AAdd( aLinesPRG, "" ) - + SWITCH cMCls CASE "QDialog" AAdd( aLinesPRG, " oRootWidget := QDialog( qParent )" ) @@ -1565,6 +1566,7 @@ METHOD HbQtSource:build() aadd( aLine, " if( s_oClass == NULL )" ) aadd( aLine, " {" ) aadd( aLine, " s_oClass = hb_itemNew( NULL );" ) + aadd( aLine, " hbqt_addDeleteList( s_oClass );" ) FOR EACH k IN hb_aTokens( s, "," ) aadd( aLine, " HB_FUNC_EXEC( " + Upper( AllTrim( k ) ) + " );" ) NEXT diff --git a/harbour/contrib/hbqt/qtcore/hbqt.h b/harbour/contrib/hbqt/qtcore/hbqt.h index 3b229f104d..3f0d1207df 100644 --- a/harbour/contrib/hbqt/qtcore/hbqt.h +++ b/harbour/contrib/hbqt/qtcore/hbqt.h @@ -108,6 +108,7 @@ extern HB_EXPORT PHB_ITEM hbqt_create_objectGC( void * pObject, const char * psz extern HB_EXPORT void hbqt_itemPushReturn( void * ptr, PHB_ITEM pSelf ); extern HB_EXPORT void hbqt_set_pptr( void * ptr, PHB_ITEM pSelf ); extern HB_EXPORT HBQT_GC_T * hbqt_getObjectGC( int iParam ); /* returns a pointer to the HBQT_GC_T area */ +extern HB_EXPORT void hbqt_addDeleteList( PHB_ITEM item ); /* populate a list of PHB_ITEM to delete at exit time */ HB_EXTERN_END diff --git a/harbour/contrib/hbqt/qtcore/hbqt_hbqevents.cpp b/harbour/contrib/hbqt/qtcore/hbqt_hbqevents.cpp index fd154d5d4b..2fc5da17bf 100644 --- a/harbour/contrib/hbqt/qtcore/hbqt_hbqevents.cpp +++ b/harbour/contrib/hbqt/qtcore/hbqt_hbqevents.cpp @@ -121,11 +121,14 @@ HBQEvents::~HBQEvents() { if( listBlock[ i ] != NULL ) { + HB_TRACE( HB_TR_DEBUG, ( " HBQEvents::~HBQEvents() %d", i ) ); + hb_itemRelease( listBlock.at( i ) ); listBlock[ i ] = NULL; + + HB_TRACE( HB_TR_DEBUG, ( " X" ) ); } } - listBlock.clear(); } bool HBQEvents::hbConnect( PHB_ITEM pObj, int iEvent, PHB_ITEM bBlock ) @@ -194,15 +197,18 @@ bool HBQEvents::hbClear() return true; } -/* DONOT Reformat */ +/* DO NOT Reformat */ bool HBQEvents::eventFilter( QObject * object, QEvent * event ) { - bool ret = false; if( object ) { QEvent::Type eventtype = event->type(); if( ( int ) eventtype > 0 ) { + if( eventtype == QEvent::Close ) + { + event->ignore(); + } char prop[ 20 ]; hb_snprintf( prop, sizeof( prop ), "%s%i%s", "P", eventtype, "P" ); @@ -219,20 +225,16 @@ bool HBQEvents::eventFilter( QObject * object, QEvent * event ) { if( hb_vmRequestReenter() ) { - ret = hb_itemGetL( hb_vmEvalBlockV( ( PHB_ITEM ) listBlock.at( found - 1 ), 1, hbqt_create_objectGC( ( * pCallback )( event, false ), s_lstCreateObj.at( eventId ) ) ) ); + hb_vmEvalBlockV( ( PHB_ITEM ) listBlock.at( found - 1 ), 1, hbqt_create_objectGC( ( * pCallback )( event, false ), s_lstCreateObj.at( eventId ) ) ); hb_vmRequestRestore(); } } - if( eventtype == QEvent::Close ) - { - event->ignore(); - } } } } } } - return ret; + return false; } HB_FUNC( __HBQT_EVENTS_CONNECT ) @@ -297,8 +299,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_itemRelease( t_events->listBlock.at( i - 1 ) ); t_events->listBlock[ i - 1 ] = NULL; + HB_TRACE( HB_TR_ALWAYS, ( " X=" ) ); } nResult = 0; @@ -321,4 +325,39 @@ HB_FUNC( __HBQT_EVENTS_NEW ) hb_retptrGC( hbqt_gcAllocate_HBQEvents( ( HBQEvents * ) new HBQEvents(), true ) ); } +static void hbqt_events_init( void * cargo ) +{ + HB_SYMBOL_UNUSED( cargo ); +} + +static void hbqt_events_exit( void * cargo ) +{ + int i; + int iItems = s_lstCreateObj.size(); + HB_TRACE( HB_TR_DEBUG, ( "ENTERING hbqt_events_exit, len=%d", s_lstCreateObj.size() ) ); + + for( i = 0; i < iItems; i++ ) + { + HB_TRACE( HB_TR_DEBUG, ( "hbqt_events_exit, deleting item %d", i )); + s_lstEvent.removeAt( 0 ); + s_lstCreateObj.removeAt( 0 ); + s_pEventAllocateCallback.removeAt( 0 ); + } + + HB_TRACE( HB_TR_DEBUG, ( "EXITING hbqt_events_exit, len=%d", s_lstCreateObj.size() ) ); + HB_SYMBOL_UNUSED( cargo ); +} + +HB_CALL_ON_STARTUP_BEGIN( _hbqtevents_init_ ) + hb_vmAtInit( hbqt_events_init, NULL ); + hb_vmAtExit( hbqt_events_exit, NULL ); +HB_CALL_ON_STARTUP_END( _hbqtevents_init_ ) + +#if defined( HB_PRAGMA_STARTUP ) + #pragma startup _hbqtevents_init_ +#elif defined( HB_DATASEG_STARTUP ) + #define HB_DATASEG_BODY HB_DATASEG_FUNC( _hbqtevents_init_ ) + #include "hbiniseg.h" +#endif + #endif diff --git a/harbour/contrib/hbqt/qtcore/hbqt_hbqslots.cpp b/harbour/contrib/hbqt/qtcore/hbqt_hbqslots.cpp index ae1bd48086..5742e0e42b 100644 --- a/harbour/contrib/hbqt/qtcore/hbqt_hbqslots.cpp +++ b/harbour/contrib/hbqt/qtcore/hbqt_hbqslots.cpp @@ -118,6 +118,7 @@ HBQSlots::~HBQSlots() { if( listBlock[ i ] != NULL ) { + HB_TRACE( HB_TR_DEBUG, ( " HBQSlots::~HBQSlots() %d", i ) ); hb_itemRelease( listBlock.at( i ) ); listBlock[ i ] = NULL; } @@ -125,7 +126,7 @@ HBQSlots::~HBQSlots() /* QUESTION: Should there be all remaining active slots disconnected at this point? */ /* Should be disconnected, but this is a responsibility of programmer as object is only known to the application */ - listBlock.clear(); + //listBlock.clear(); } int HBQSlots::qt_metacall( QMetaObject::Call c, int id, void ** arguments ) diff --git a/harbour/contrib/hbqt/qtcore/hbqt_init.cpp b/harbour/contrib/hbqt/qtcore/hbqt_init.cpp index d3328def60..9453b94852 100644 --- a/harbour/contrib/hbqt/qtcore/hbqt_init.cpp +++ b/harbour/contrib/hbqt/qtcore/hbqt_init.cpp @@ -57,6 +57,7 @@ #include "hbqt.h" #include "hbqtinit.h" +#include "hbapiitm.h" #include "hbvm.h" #include "hbinit.h" #include "hbstack.h" @@ -408,6 +409,14 @@ static void hbqt_registerCallbacks( void ) HB_FUNC( __HBQTCORE ) {;} +static QList s_PHB_ITEM_tobedeleted; + +void hbqt_addDeleteList( PHB_ITEM item ) +{ + s_PHB_ITEM_tobedeleted << item ; +} + + static void hbqt_lib_init( void * cargo ) { HB_SYMBOL_UNUSED( cargo ); @@ -422,6 +431,15 @@ static void hbqt_lib_init( void * cargo ) static void hbqt_lib_exit( void * cargo ) { HB_SYMBOL_UNUSED( cargo ); + + HB_TRACE( HB_TR_ALWAYS, ( "hbqt_lib_exit, len=%d", s_PHB_ITEM_tobedeleted.size() ) ); + + int i; + for( i = 0; i < s_PHB_ITEM_tobedeleted.size(); ++i ) + { + hb_itemRelease( s_PHB_ITEM_tobedeleted.at( i ) ); + HB_TRACE( HB_TR_ALWAYS, ( "hbqt_lib_exit, deleted item %d", i )); + } } HB_CALL_ON_STARTUP_BEGIN( _hbqtcore_init_ ) diff --git a/harbour/contrib/hbqt/qtcore/hbqt_pointer.cpp b/harbour/contrib/hbqt/qtcore/hbqt_pointer.cpp index 4eb001acc7..7350823065 100644 --- a/harbour/contrib/hbqt/qtcore/hbqt_pointer.cpp +++ b/harbour/contrib/hbqt/qtcore/hbqt_pointer.cpp @@ -157,7 +157,8 @@ void * hbqt_gcpointer( int iParam ) else if( HB_ISPOINTER( iParam ) ) { HB_TRACE( HB_TR_DEBUG, ( "hbqt_gcpointer(): returns RAW pointer: %p", hb_parptr( iParam ) ) ); - return hb_parptr( iParam ); /* TOFIX: In what cases is this needed? Reference counting to avoid referring to freed pointers? */ + return NULL; + //return hb_parptr( iParam ); /* TOFIX: In what cases is this needed? Reference counting to avoid referring to freed pointers? */ } else if( HB_ISOBJECT( iParam ) ) { @@ -166,7 +167,8 @@ void * hbqt_gcpointer( int iParam ) hb_vmPushSymbol( hb_dynsymSymbol( hb_dynsymFindName( "PPTR" ) ) ); hb_vmPush( pObj ); hb_vmSend( 0 ); - return hbqt_gcpointer( -1 ); + void * ptr = hbqt_gcpointer( -1 ); + return ptr; } else { @@ -184,8 +186,8 @@ void * hbqt_pPtrFromObj( int iParam ) HB_TRACE( HB_TR_DEBUG, ( "hbqt_pPtrFromObj( %d )", iParam ) ); - if( ! s_pDyns_hPPtrAssign ) - s_pDyns_hPPtrAssign = hb_dynsymGetCase( "PPTR" ); + if( ! s_pDyns_hPPtrAssign ) + s_pDyns_hPPtrAssign = hb_dynsymGetCase( "PPTR" ); pObj = hb_param( iParam, HB_IT_ANY ); @@ -418,9 +420,8 @@ HB_FUNC( HBQT_ISEQUAL ) HB_FUNC( __HBQT_ERROR ) { - PHB_ITEM pError = hb_errRT_New( ES_ERROR, "HBQT", EG_ARG, hb_parnidef( 1, 1001 ), NULL, NULL, 0, EF_NONE ); - hb_errLaunch( pError ); - hb_itemRelease( pError ); + HB_TRACE( HB_TR_ALWAYS, ( "In __HBQT_ERROR" )); + hb_errRT_BASE( EG_ARG, 9999, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); } HB_FUNC( __HBQT_SETUTF8 ) diff --git a/harbour/contrib/hbqt/qtgui/THbQtUI.prg b/harbour/contrib/hbqt/qtgui/THbQtUI.prg index acfecad7f6..b623848b8f 100644 --- a/harbour/contrib/hbqt/qtgui/THbQtUI.prg +++ b/harbour/contrib/hbqt/qtgui/THbQtUI.prg @@ -67,6 +67,7 @@ #include "hbclass.ch" #include "error.ch" +#include "hbtrace.ch" /*----------------------------------------------------------------------*/ @@ -98,10 +99,16 @@ METHOD HbQtUI:new( oRootWidget, hWidget ) /* QUESTION: Is this needed? */ METHOD HbQtUI:destroy() + LOCAL oObj ::oWidget:close() ::oWidget := NIL + FOR EACH oObj IN ::qObj DESCEND + oObj := NIL + NEXT + ::qObj := {=>} + RETURN NIL /*----------------------------------------------------------------------*/ diff --git a/harbour/contrib/hbqt/qtgui/hbqt_hbqtableview.cpp b/harbour/contrib/hbqt/qtgui/hbqt_hbqtableview.cpp index 7c0bbd4cb1..8e24685a86 100644 --- a/harbour/contrib/hbqt/qtgui/hbqt_hbqtableview.cpp +++ b/harbour/contrib/hbqt/qtgui/hbqt_hbqtableview.cpp @@ -61,6 +61,12 @@ #include +HB_EXTERN_BEGIN +extern void * hbqt_gcAllocate_QMouseEvent( void * pObj, bool bNew ); +extern void * hbqt_gcAllocate_QWheelEvent( void * pObj, bool bNew ); +HB_EXTERN_END + + HBQTableView::HBQTableView( QWidget * parent ) : QTableView( parent ) { block = NULL; @@ -92,7 +98,7 @@ void HBQTableView::mousePressEvent( QMouseEvent * event ) if( block ) { PHB_ITEM p0 = hb_itemPutNI( NULL, QEvent::MouseButtonPress ); - PHB_ITEM p1 = hbqt_create_object( event, "hb_QMouseEvent" ); + PHB_ITEM p1 = hbqt_create_objectGC( hbqt_gcAllocate_QMouseEvent( event, false ), "hb_QMouseEvent" ); hb_vmEvalBlockV( block, 2, p0, p1 ); hb_itemRelease( p0 ); hb_itemRelease( p1 ); @@ -105,7 +111,7 @@ void HBQTableView::mouseDoubleClickEvent( QMouseEvent * event ) if( block ) { PHB_ITEM p0 = hb_itemPutNI( NULL, QEvent::MouseButtonDblClick ); - PHB_ITEM p1 = hbqt_create_object( event, "hb_QMouseEvent" ); + PHB_ITEM p1 = hbqt_create_objectGC( hbqt_gcAllocate_QMouseEvent( event, false ), "hb_QMouseEvent" ); hb_vmEvalBlockV( block, 2, p0, p1 ); hb_itemRelease( p0 ); hb_itemRelease( p1 ); @@ -118,7 +124,7 @@ void HBQTableView::wheelEvent( QWheelEvent * event ) if( block ) { PHB_ITEM p0 = hb_itemPutNI( NULL, QEvent::Wheel ); - PHB_ITEM p1 = hbqt_create_object( event, "hb_QWheelEvent" ); + PHB_ITEM p1 = hbqt_create_objectGC( hbqt_gcAllocate_QWheelEvent( event, false ), "hb_QWheelEvent" ); hb_vmEvalBlockV( block, 2, p0, p1 ); hb_itemRelease( p0 ); hb_itemRelease( p1 ); diff --git a/harbour/contrib/hbqt/tests/demoqt.prg b/harbour/contrib/hbqt/tests/demoqt.prg index f95d973656..93587ec2c5 100644 --- a/harbour/contrib/hbqt/tests/demoqt.prg +++ b/harbour/contrib/hbqt/tests/demoqt.prg @@ -73,28 +73,12 @@ #include "common.ch" - -STATIC s_qApp - STATIC oSys, oMenuSys, oActShow, oActHide /*----------------------------------------------------------------------*/ -INIT PROCEDURE Qt_Start() - - hbqt_errorsys() - - s_qApp := QApplication() - RETURN - -EXIT PROCEDURE Qt_End() - s_qApp:quit() - RETURN - -/*----------------------------------------------------------------------*/ - -FUNCTION My_Events() - HB_TRACE( HB_TR_ALWAYS, "Key Pressed" ) +FUNCTION My_Events( e ) + HB_TRACE( HB_TR_ALWAYS, "Key Pressed", e:key() ) RETURN nil /*----------------------------------------------------------------------*/ @@ -103,6 +87,8 @@ PROCEDURE Main() Local oLabel, oBtn, oDA, oWnd, oProg, oSBar LOCAL aMenu, aTool, aGrid, aTabs, aList + hbqt_errorsys() + oWnd := QMainWindow() oWnd:show() @@ -130,10 +116,10 @@ PROCEDURE Main() aList := Build_ListBox( oDA, { 310,240 }, { 150, 100 } ) oWnd:connect( 6, {|e| My_Events( e ) } ) - oWnd:connect( 19, {|| s_qApp:quit() } ) + oWnd:connect( 19, {|| QApplication():quit() } ) oWnd:Show() - s_qApp:exec() + QApplication():exec() xReleaseMemory( { oBtn, oLabel, oProg, oSBar, aGrid, aList, aMenu, aTool, aTabs, oDA, oWnd } ) @@ -235,7 +221,7 @@ STATIC FUNCTION Build_MenuBar( oWnd ) oMenu1:addSeparator() oActExit := oMenu1:addAction( "E&xit" ) - oActExit:connect( "triggered(bool)", {|| s_qApp:quit() } ) + oActExit:connect( "triggered(bool)", {|| QApplication():quit() } ) oMenuBar:addMenu( oMenu1 )