2009-10-29 09:58 UTC-0800 Pritpal Bedi (pritpal@vouchcac.com)

* contrib/hbqt/hbqt_slots.cpp

  * contrib/hbqt/qtgui/QTreeWidgetItem.cpp

  * contrib/hbxbp/xbpbrowse.prg
  * contrib/hbxbp/xbpdialog.prg
  * contrib/hbxbp/xbpgeneric.prg
  * contrib/hbxbp/xbpmenubar.prg
  * contrib/hbxbp/xbpstatusbar.prg
  * contrib/hbxbp/xbptoolbar.prg
  * contrib/hbxbp/xbpwindow.prg

  * contrib/hbxbp/tests/demoxbp.prg
    ! Demoxbp.exe now terminates properly after releasing all Qt objects
      and releasing Qt objects memory. Analysis follows.
n
This commit is contained in:
Pritpal Bedi
2009-10-29 17:04:20 +00:00
parent b307b30e68
commit 640b0815c0
11 changed files with 140 additions and 88 deletions

View File

@@ -17,6 +17,23 @@
past entries belonging to author(s): Viktor Szakats.
*/
2009-10-29 09:58 UTC-0800 Pritpal Bedi (pritpal@vouchcac.com)
* contrib/hbqt/hbqt_slots.cpp
* contrib/hbqt/qtgui/QTreeWidgetItem.cpp
* contrib/hbxbp/xbpbrowse.prg
* contrib/hbxbp/xbpdialog.prg
* contrib/hbxbp/xbpgeneric.prg
* contrib/hbxbp/xbpmenubar.prg
* contrib/hbxbp/xbpstatusbar.prg
* contrib/hbxbp/xbptoolbar.prg
* contrib/hbxbp/xbpwindow.prg
* contrib/hbxbp/tests/demoxbp.prg
! Demoxbp.exe now terminates properly after releasing all Qt objects
and releasing Qt objects memory. Analysis follows.
2009-10-29 16:58 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/doc/xhb-diff.txt
* fixed some typos

View File

@@ -1697,11 +1697,6 @@ HB_FUNC( QT_CONNECT_SIGNAL )
}
}
#if 0
bool connect ( const QObject * sender, const char * signal, const char * method, Qt::ConnectionType type = Qt::AutoConnection ) const
bool disconnect ( const char * signal = 0, const QObject * receiver = 0, const char * method = 0 )
bool disconnect ( const QObject * receiver, const char * method = 0 )
#endif
/*
* harbour function to disconnect signals
*/
@@ -1722,7 +1717,6 @@ HB_FUNC( QT_DISCONNECT_SIGNAL )
s_s->listBlock[ i - 1 ] = NULL;
s_s->listActv[ i - 1 ] = false;
bFreed = true;
object->disconnect( event );
#if defined(__debug__)
hb_snprintf( str, sizeof( str ), "QT_DISCONNECT_SIGNAL: %s", event ); OutputDebugString( str );
@@ -2017,9 +2011,8 @@ HbDbfModel::HbDbfModel( PHB_ITEM pBlock ) : QAbstractItemModel()
}
HbDbfModel::~HbDbfModel( void )
{
hb_snprintf( str, sizeof( str ), "HbDbfModel::~HbDbfModel() 0" ); OutputDebugString( str );
hb_itemRelease( block );
hb_snprintf( str, sizeof( str ), "HbDbfModel::~HbDbfModel() 1" ); OutputDebugString( str );
destroy();
}
Qt::ItemFlags HbDbfModel::flags( const QModelIndex & index ) const
{
@@ -2200,10 +2193,7 @@ void HbDbfModel::hbSetRowColumns( int rows, int cols )
void HbDbfModel::destroy()
{
hb_snprintf( str, sizeof( str ), "HbDbfModel::destroy() 0" ); OutputDebugString( str );
hb_itemRelease( block );
hb_snprintf( str, sizeof( str ), "HbDbfModel::destroy() 1" ); OutputDebugString( str );
//HbDbfModel::~HbDbfModel();
}
/*----------------------------------------------------------------------*/
@@ -2230,6 +2220,8 @@ MyMainWindow::MyMainWindow( PHB_ITEM pBlock, int iThreadID )
}
MyMainWindow::~MyMainWindow( void )
{
delete painter;
hb_itemRelease( block );
destroy();
}
void MyMainWindow::paintEvent( QPaintEvent * event )
@@ -2430,10 +2422,12 @@ HB_FUNC( QT_MYMAINWINDOW )
PHB_ITEM bBlock = hb_itemNew( ( PHB_ITEM ) hb_param( 1, HB_IT_BLOCK ) );
hb_retptr( ( MyMainWindow * ) new MyMainWindow( bBlock, hb_parni( 2 ) ) );
}
HB_FUNC( QT_MYMAINWINDOW_DESTROY )
{
hb_itemRelease( hbqt_par_MyMainWindow( 1 )->block );
hbqt_par_MyMainWindow( 1 )->~MyMainWindow();
}
HB_FUNC( QT_MUTEXCREATE )
{
if( s_mutex == NULL )
@@ -2441,6 +2435,16 @@ HB_FUNC( QT_MUTEXCREATE )
s_mutex = hb_threadMutexCreate( FALSE );
}
}
HB_FUNC( QT_MUTEXDESTROY )
{
if( s_mutex != NULL )
{
hb_itemRelease( s_mutex );
s_mutex = NULL;
}
}
/*----------------------------------------------------------------------*/
/*----------------------------------------------------------------------*/
/*----------------------------------------------------------------------*/

View File

@@ -106,7 +106,7 @@ QT_G_FUNC( release_QTreeWidgetItem )
hb_snprintf( str, sizeof(str), "release_QTreeWidgetItem" ); OutputDebugString( str );
#endif
void * ph = ( void * ) Cargo;
if( ph )
if( ph != NULL )
{
delete ( ( QTreeWidgetItem * ) ph );
ph = NULL;
@@ -120,11 +120,15 @@ HB_FUNC( QT_QTREEWIDGETITEM )
if( hb_pcount() >= 1 && HB_ISNUM( 1 ) )
{
pObj = ( QTreeWidgetItem* ) new QTreeWidgetItem( hb_parni( 1 ) ) ;
pObj = new QTreeWidgetItem( hb_parni( 1 ) ) ;
}
else if( hb_pcount() >= 1 && HB_ISPOINTER( 1 ) )
{
pObj = new QTreeWidgetItem( hbqt_par_QTreeWidget( 1 ), hb_parni( 2 ) ) ;
}
else
{
pObj = ( QTreeWidgetItem* ) new QTreeWidgetItem( hbqt_par_QTreeWidget( 1 ), hb_parni( 2 ) ) ;
pObj = new QTreeWidgetItem() ;
}
p->ph = pObj;

View File

@@ -101,7 +101,7 @@ PROCEDURE Main()
FUNCTION _BuildADialog()
hb_gtReload( 'GUI' )
// hb_gtReload( 'GUI' )
BuildADialog()
RETURN NIL
@@ -215,9 +215,12 @@ xbp_debug( ".............................. WOW .................................
/* Very important - destroy resources */
oDlg:destroy()
oDlg := NIL
xbp_debug( "------------------------------ WOW ---------------------------------" )
xbp_debug( ". " )
oHTM := NIL
oMLE := NIL
//oDlg := NIL
RETURN
/*----------------------------------------------------------------------*/

View File

@@ -367,10 +367,10 @@ PROTECTED:
DATA oDbfModel
DATA oModelIndex INIT QModelIndex()
DATA oVHeaderView
DATA oHeaderView INIT QHeaderView()
DATA oVScrollBar INIT QScrollBar()
DATA oHScrollBar INIT QScrollBar()
DATA oViewport INIT QWidget()
DATA oHeaderView INIT QHeaderView()
DATA oVScrollBar INIT QScrollBar()
DATA oHScrollBar INIT QScrollBar()
DATA oViewport INIT QWidget()
DATA oFont INIT QFont()
DATA pCurIndex
@@ -712,42 +712,44 @@ METHOD XbpBrowse:destroy()
::sl_xbeBRW_Navigate := NIL
::sl_xbeBRW_Pan := NIL
FOR i := 1 TO ::colCount
::columns[ i ]:destroy()
::columns[ i ] := NIL
NEXT
::oHScrollBar:pPtr := 0
::oVScrollBar:pPtr := 0
IF !empty( ::oModelIndex )
::oModelIndex:pPtr := 0
ENDIF
::oHScrollBar:pPtr := 0
::oVScrollBar:pPtr := 0
//::oLeftView:destroy()
::oLeftDbfModel:destroy()
::oLeftVHeaderView:pPtr := 0
::oLeftHeaderView:pPtr := 0
::oLeftFooterView:pPtr := 0
::oLeftVHeaderView:pPtr := 0
::oLeftHeaderView:pPtr := 0
::oLeftFooterView:pPtr := 0
::oLeftFooterModel:destroy()
//::oRightView:destroy()
::oRightHeaderView:pPtr := 0
::oRightHeaderView:pPtr := 0
::oRightDbfModel:destroy()
::oRightFooterView:pPtr := 0
::oRightFooterView:pPtr := 0
::oRightFooterModel:destroy()
//::oTableView:destroy()
::oVHeaderView:pPtr := 0
::oVHeaderView:pPtr := 0
::oDbfModel:destroy()
::oFooterView:pPtr := 0
::oFooterView:pPtr := 0
::oFooterModel:destroy()
::oGridLayout:pPtr := 0
::oGridLayout:pPtr := 0
::oGridLayout := NIL
::oFooterModel := NIL
::oFooterView := NIL
::clearSlots()
::xbpWindow:destroy()
RETURN nil

View File

@@ -148,8 +148,6 @@ METHOD XbpDialog:create( oParent, oOwner, aPos, aSize, aPresParams, lVisible )
SetAppWindow( Self )
QT_MUTEXCREATE() //-------------//
/* Initialize Qt's event stacks */
QT_SetEventSlots()
QT_SetEventFilter()
@@ -158,11 +156,9 @@ METHOD XbpDialog:create( oParent, oOwner, aPos, aSize, aPresParams, lVisible )
InitializeEventBuffer()
/* Install Event Loop per Dialog Basis */
/* Limitng */
::oEventLoop := QEventLoop():new( ::pWidget )
SetEventLoop( ::oEventLoop )
#if 1
/* Instal Event Filter */
::oWidget:installEventFilter( SetEventFilter() )
@@ -171,7 +167,7 @@ METHOD XbpDialog:create( oParent, oOwner, aPos, aSize, aPresParams, lVisible )
::connectEvent( ::pWidget, QEvent_Close , {|o,e| ::exeBlock( QEvent_Close , e, o ) } )
::connectEvent( ::pWidget, QEvent_WindowActivate , {|o,e| ::exeBlock( QEvent_WindowActivate , e, o ) } )
::connectEvent( ::pWidget, QEvent_WindowDeactivate, {|o,e| ::exeBlock( QEvent_WindowDeactivate, e, o ) } )
#endif
RETURN Self
/*----------------------------------------------------------------------*/
@@ -218,13 +214,20 @@ METHOD XbpDialog:destroy()
SetEventLoop( NIL )
::oEventLoop:exit( 0 )
::oEventLoop:pPtr := 0
::oMenu := NIL
::drawingArea := NIL
SetAppWindow( XbpObject():new() )
::oMenu := NIL
::drawingArea := NIL
::xbpWindow:destroy()
Qt_MyMainWindow_destroy( QT_PTROF( ::oWidget ) )
::oWidget := NIL
Self := NIL
RETURN nil
/*----------------------------------------------------------------------*/

View File

@@ -99,10 +99,12 @@ THREAD STATIC oEventLoop
INIT PROCEDURE Qt_Start()
Qt_MutexCreate()
ts_mutex := hb_mutexCreate()
oDummy := XbpObject():new()
oApp := QApplication():new()
oApp := QApplication():new()
RETURN
@@ -110,9 +112,14 @@ INIT PROCEDURE Qt_Start()
EXIT PROCEDURE Qt_End()
Qt_MutexDestroy()
oDummy := NIL
oAppWindow := NIL
oDeskTop:pPtr := 0
oApp:quit()
oApp:pPtr := 0
oApp:pPtr := 0
RETURN

View File

@@ -218,14 +218,18 @@ METHOD xbpMenuBar:configure( oParent, aPresParams, lVisible )
/*----------------------------------------------------------------------*/
METHOD xbpMenuBar:destroy()
LOCAL i
#if 0
IF !empty( ::oWidget )
::DelAllItems()
::oWidget:close()
::oWidget := NIL
ENDIF
#endif
::disconnect()
FOR i := 1 TO len( ::aMenuItems )
IF !empty( ::aMenuItems[ i,5 ] )
QT_DISCONNECT_SIGNAL( QT_PTROF( ::aMenuItems[ i, 5 ] ), "triggered(bool)" )
QT_DISCONNECT_SIGNAL( QT_PTROF( ::aMenuItems[ i, 5 ] ), "hovered()" )
::aMenuItems[ i, 5 ]:pPtr := 0
::aMenuItems[ i, 5 ] := NIL
ENDIF
NEXT
::xbpWindow:destroy()
@@ -247,23 +251,25 @@ METHOD xbpMenuBar:delAllItems()
/*----------------------------------------------------------------------*/
METHOD xbpMenuBar:delItem( nItemIndex )
LOCAL lResult:= .F.
LOCAL lResult := .T.
LOCAL oAction
HB_SYMBOL_UNUSED( nItemIndex )
//xbp_debug( nItemIndex, len( ::aMenuItems ), len( ::aMenuItems[ nItemIndex ] ) )
#if 0
IF nItemIndex > 0 .AND. nItemIndex <= ::numItems()
IF ::aMenuItems[ nItemIndex,QTC_MENU_TYPE ] == QMF_POPUP
::aMenuItems[ nItemIndex,QTC_MENU_MENUOBJ ]:Destroy()
ENDIF
IF ( lResult:= Qtc_DeleteMenu( ::hMenu, nItemIndex-1, QMF_BYPOSITION ) ) /* Remember ZERO base */
ADEL( ::aMenuItems, nItemIndex )
ASIZE( ::aMenuItems, LEN( ::aMenuItems ) - 1 )
IF ::aMenuItems[ nItemIndex, 1 ] == QMF_POPUP
//xbp_debug( valtype( ::aMenuItems[ nItemIndex, 4 ] ), __ObjGetClsName( ::aMenuItems[ nItemIndex, 4 ] ) )
//::aMenuItems[ nItemIndex, 4 ]:destroy()
ELSE
oAction := ::aMenuItems[ nItemIndex, 5 ]
QT_DISCONNECT_SIGNAL( QT_PTROF( oAction ), "triggered(bool)" )
QT_DISCONNECT_SIGNAL( QT_PTROF( oAction ), "hovered()" )
oAction:pPtr := 0
ENDIF
// ADEL( ::aMenuItems, nItemIndex )
// ASIZE( ::aMenuItems, LEN( ::aMenuItems ) - 1 )
ENDIF
#endif
RETURN lResult
/*----------------------------------------------------------------------*/
@@ -290,7 +296,8 @@ METHOD xbpMenuBar:placeItem( xCaption, bAction, nStyle, nAttrb, nMode, nPos )
ELSE
oAction:pPtr := ::oWidget:addSeparator()
ENDIF
aItem := { QMF_SEPARATOR, 0, 0, NIL, NIL, oAction }
//aItem := { QMF_SEPARATOR, 0, 0, NIL, NIL, oAction }
aItem := { QMF_SEPARATOR, 0, 0, NIL, oAction }
CASE cType == "C"
oAction := QAction():new( QT_PTROF( ::oWidget ) )
@@ -351,7 +358,7 @@ METHOD xbpMenuBar:placeItem( xCaption, bAction, nStyle, nAttrb, nMode, nPos )
CASE cType == "O"
cCaption := IF( bAction == NIL, xCaption:title, bAction )
aItem := { QMF_POPUP, xCaption:oWidget, cCaption, xCaption }
aItem := { QMF_POPUP, xCaption:oWidget, cCaption, xCaption, NIL }
IF hb_isChar( cCaption )
xCaption:oWidget:setTitle( strtran( cCaption, '~','&' ) )
ENDIF
@@ -363,7 +370,7 @@ METHOD xbpMenuBar:placeItem( xCaption, bAction, nStyle, nAttrb, nMode, nPos )
IF nMode == QTC_MENUITEM_ADD
aadd( ::aMenuItems, aItem )
aadd( ::aOrgItems , { xCaption, bAction, nStyle, nAttrb } )
aadd( ::aOrgItems , { xCaption, bAction, nStyle, nAttrb, NIL } )
ELSEIF nMode == QTC_MENUITEM_INSERT
asize( ::aMenuItems, ::numItems + 1 )
@@ -371,7 +378,7 @@ METHOD xbpMenuBar:placeItem( xCaption, bAction, nStyle, nAttrb, nMode, nPos )
ains( ::aMenuItems, nPos )
ains( ::aOrgItems, nPos )
::aMenuItems[ nPos ] := aItem
::aOrgItems[ nPos ] := { xCaption, bAction, nStyle, nAttrb }
::aOrgItems[ nPos ] := { xCaption, bAction, nStyle, nAttrb, NIL }
ELSEIF nMode == QTC_MENUITEM_REPLACE

View File

@@ -122,9 +122,6 @@ METHOD XbpStatusBar:create( oParent, oOwner, aPos, aSize, aPresParams, lVisible
RETURN Self
ENDIF
::oWidget := QToolBar():new( QT_PTROF( oPar:oWidget ) )
oPar:oWidget:addToolBar_1( ::pWidget )
::oWidget := QStatusBar():new( QT_PTROF( oPar:oWidget ) )
oPar:oWidget:setStatusBar( ::pWidget )
@@ -166,6 +163,8 @@ METHOD XbpStatusBar:destroy()
NEXT
ENDIF
::oParent := NIL
::xbpWindow:destroy()
RETURN NIL

View File

@@ -200,6 +200,11 @@ METHOD XbpToolbar:destroy()
IF ::aItems[ i,2 ]:hotImage <> NIL
//Win_DeleteObject( ::aItems[ i,2 ]:hotImage )
ENDIF
// QT_DISCONNECT_SIGNAL( QT_PTROF( ::aMenuItems[ i, 5 ] ), "triggered(bool)" )
// QT_DISCONNECT_SIGNAL( QT_PTROF( ::aMenuItems[ i, 5 ] ), "hovered()" )
::aItems[ i,2 ]:oAction:pPtr := 0
::aItems[ i,2 ]:oAction := NIL
NEXT
ENDIF
@@ -435,3 +440,4 @@ METHOD XbpToolbarButton:new( cCaption, nStyle, cKey )
RETURN Self
/*----------------------------------------------------------------------*/

View File

@@ -265,7 +265,6 @@ EXPORTED:
DATA xDummy
METHOD connect()
METHOD disConnect()
METHOD connectEvent()
METHOD connectWindowEvents()
DATA aConnections INIT {}
@@ -275,6 +274,7 @@ EXPORTED:
DATA lTrack INIT .f.
METHOD disConnect()
METHOD clearSlots()
DATA aPP
@@ -313,14 +313,12 @@ METHOD XbpWindow:create( oParent, oOwner, aPos, aSize, aPresParams, lVisible )
DEFAULT oOwner TO ::oOwner
DEFAULT aPos TO ::aPos
DEFAULT aSize TO ::aSize
// DEFAULT aPresParams TO {}
DEFAULT lVisible TO ::visible
::oParent := oParent
::oOwner := oOwner
::aPos := aPos
::aSize := aSize
// ::aPresParams := aPresParams
::visible := lVisible
::XbpPartHandler:create( oParent, oOwner )
@@ -698,6 +696,7 @@ METHOD XbpWindow:configure( oParent, oOwner, aPos, aSize, aPresParams, lVisible
/*----------------------------------------------------------------------*/
METHOD XbpWindow:destroy()
LOCAL cXbp := __ObjGetClsName( self )
xbp_Debug( ". " )
xbp_Debug( memory( 1001 ),"Destroy: "+pad(__ObjGetClsName( self ),12)+ IF(empty(::cargo),'',str(::cargo) ) )
@@ -716,30 +715,21 @@ xbp_Debug( memory( 1001 ),"Destroy: "+pad(__ObjGetClsName( self ),12)+ IF(empty(
::aChildren := {}
ENDIF
::oWidget:pPtr := 0
IF cXbp != "XBPDIALOG"
::oWidget:pPtr := 0
::oWidget := NIL
ENDIF
::XbpPartHandler:destroy()
::clearSlots()
::xbpPartHandler:destroy()
xbp_Debug( memory( 1001 )," Destroy: "+pad(__ObjGetClsName( self ),12)+ IF(empty(::cargo),'',str(::cargo) ) )
::oWidget := NIL
Self := NIL
// Self := NIL
RETURN NIL
/*----------------------------------------------------------------------*/
METHOD XbpWindow:disConnect()
IF len( ::aConnections ) > 0
aeval( ::aConnections, {|e_| Qt_DisConnect_Signal( e_[ 1 ], e_[ 2 ] ), e_[ 1 ] := NIL, e_[ 2 ] := NIL } )
::aConnections := {}
ENDIF
RETURN Self
/*----------------------------------------------------------------------*/
METHOD XbpWindow:clearSlots()
LOCAL i
@@ -782,9 +772,19 @@ METHOD XbpWindow:clearSlots()
::aPresParams[ i,1 ] := NIL
::aPresParams[ i,2 ] := NIL
::aPresParams[ i ] := NIL
//xbp_debug( i, "--------- aPresParam -----------" )
NEXT
::aPresParams := NIL
ENDIF
::aPresParams := NIL
RETURN Self
/*----------------------------------------------------------------------*/
METHOD XbpWindow:disconnect()
IF len( ::aConnections ) > 0
aeval( ::aConnections, {|e_| Qt_DisConnect_Signal( e_[ 1 ], e_[ 2 ] ), e_[ 1 ] := NIL, e_[ 2 ] := NIL } )
::aConnections := {}
ENDIF
RETURN Self