l3whmg wrote:Hi Mauricio, perhaps I don't understand your code, but I see a lot of release method (I'm referring to the second example)
Sorry !!!
My mistake, where you see Method Release please interpret as Method CloseQtObject...
Post updated...
Moderator: Rathinagiri
l3whmg wrote:Hi Mauricio, perhaps I don't understand your code, but I see a lot of release method (I'm referring to the second example)
Carlos Britos wrote: If we do Win_1:Lbl1 := nil then harbour object is destroyed (I'm guess) but the Qt object is there.
But we are discussing here add more code to Release() beyond just ::oQtObject:close(), and, if so, duplicated code will rise.I don't see possible duplicate code1....
Code: Select all
oPopupFile:Release()
oPopupHelp:Release()
oPopupMore:Release()
oPopupEdit:Release()
oItemOpen:Release()
oItemClose:Release()
oItemMore1:Release()
oItemMore2:Release()
oItemMore3:Release()
oItemCut:Release()
oItemCopy:Release()
oItemPaste:Release()
oItemAbout:Release()
oItemSave:Release()
oButton1:Release()
oButton2:Release()
oButton3:Release()
oButton4:Release()
oButton5:Release()
oButton6:Release()
oButton7:Release()
oButton8:Release()
oButton9:Release()
oButton10:Release()
mrduck wrote: We can set Qt::WA_DeleteOnClose but keep in mind that it is asyncronuos, memory is released when Qt feels it is necessary and not when the window is closed.
At the same time in ::Release() we must set ::oQTObject := NIL so that we don't map the Qt object anymore.... I'm thinking that this can be enough to delete the Qt object... can you try ?
I think that doing a loop on ::aControls is not necessary at all, probably a
::aControls := NIL // to force deletion
::aControls := {}
should produce the same results.
Code: Select all
#include "hmg.ch"
FUNCTION Main
LOCAL Win_1, LBL1, LBL2, LBL3, oBTN, tmr, LBL4
Define Window Win_1 ;
At 10, 10 ;
Width 650 ;
Height 400 ;
Main
Define Main Menu
Define Popup "test"
Item "Release LBL1" Action { || Win_1:LBL1 := NIL,;
WIN_1:LBL1:Show(),;
WIN_1:LBL1:Value( '********' ) }
Item "Release LBL2:LBL3" Action { || LBL2:LBL3:Release(),;
LBL2:LBL3:Show(),;
LBL2:LBL3:Value( 'ooooooooooo' ) }
Item "Release LBL4" Action { || LBL4:Release(), LBL4:oQTObject := NIL, LBL4 := NIL }
End Popup
End Menu
With Object oBTN := Button():New( "oBTN" )
:Row := 40
:Col := 290
:Width := 150
:Caption := 'Open Standard Window'
End With
oBTN:OnClick := { || Button1Click() }
With Object LBL1 := label():New( "LBL1" )
:value := 'LBL1 parent of Win_1'
:Row := 40
:Col := 100
:Width := 200
End
LBL1:OnClick := { || Win_1:LBL1:release() }
With Object LBL2 := label():New( "LBL2" )
:value := 'LBL2 parent of Win_1'
:Row := 80
:Col := 100
:Width := 200
End
LBL2:OnClick := { || Win_1:LBL2:release() }
With Object LBL3 := label():New( "LBL3" )
:value := 'LBL3 parent of LBL2'
:Row := 120
:Col := 100
:Width := 200
:OnClick := { || LBL3:release() }
End
LBL3:Parent := LBL2
With Object tmr := Timer():New( "tmr" )
:Interval := 1000
End
tmr:Parent := LBL3
With Object LBL4 := label():New( "LBL4" )
:value := 'LBL4'
:Row := 160
:Col := 100
:Width := 200
:OnClick := { || LBL4:release() }
End
End Window
Activate Window Win_1
Win_1:Release()
RETURN 0
/*----------------------------------------------------------------------*/
PROCEDURE Button1Click()
LOCAL oStd , oBTN
With Object oStd := Window():New()
:Row := 10
:Col := 10
:Width := 600
:Height := 300
:Title := 'Nice OOP Standard Window!!!'
:Type := WND_STANDARD
:OnInit := { || oStd:Center() }
With Object oBTN := Button():New()
:Row := 40
:Col := 40
:Caption := 'Close Window'
End With
oBTN:OnClick := { || oStd:Release() }
End With
oStd:Activate()
oStd:Release()
RETURN
/*----------------------------------------------------------------------
METHOD Release() CLASS BASIC
LOCAL i
// Release all child objects in it.
// Recursive !
FOR i := 1 TO Len( ::aControls )
IF hb_IsObject( ::aControls[ i ] )
::aControls[ i ]:Release()
ENDIF
NEXT
// Remove from the parent pool control
FOR i := 1 TO Len( ::oParent:aControls )
IF hb_IsObject( ::oParent:aControls[ i ] )
IF ::oParent:aControls[ i ]:Name == ::Name
::oParent:aControls[ i ] := Nil
// ::oParent:oQTObject := NIL // => GPF
ENDIF
ENDIF
NEXT
// Some QT classes do not have close()
IF ! ( ::cClass == "MENUITEM" .OR. ;
::cClass == "SOUND" .OR. ;
::cClass == "TIMER" .OR. ;
::cClass == "LAYOUTBOX" .OR. ;
::cClass == "LAYOUTFORM" .OR. ;
::cClass == "LAYOUTGRID" )
// release QT object
::oQTObject:close()
// ::oQTObject := NIL // => GPF
ENDIF
RETURN NIL */
Because of this I'm adding the for next in release methodl3whmg wrote:About me, I never think to "add other code then ::oQtobject:Close()", IMHO because RELEASE must bu used only with QmainWindow, in other word Window HMG object. I have open this topic because I find, within a demo, this code:
I have given my impression and opinion about some ideas to add code or to force QT event and related problem with the solution.Code: Select all
oPopupFile:Release() oPopupHelp:Release() oPopupMore:Release() oPopupEdit:Release() ..... oButton10:Release()
Cheers
I'm not agree, each object must have a release method, One for all as far as is possible.l3whmg wrote:IMHO because RELEASE must bu used only with QmainWindow, in other word Window HMG object.
Cheers
Please add here a hbqt_errorsys() call and you will see some harbour errors...Carlos Britos wrote:Code: Select all
#include "hmg.ch" FUNCTION Main
Code: Select all
With Object LBL3 := label():New( "LBL3", LBL2 )
Code: Select all
// Remove from the parent pool control
FOR i := 1 TO Len( ::oParent:aControls )
IF hb_IsObject( ::oParent:aControls[ i ] )
IF ::oParent:aControls[ i ]:Name == ::Name
::oParent:aControls[ i ] := Nil
// ::oParent:oQTObject := NIL // => GPF
ENDIF
ENDIF
NEXT
Code: Select all
METHOD NEW CLASS CONTROL
....
IF hb_isobject( ::oParent ) == .T.
AADD( ::oParent:aControls , Self )
::oParent:AddData( ::cName , Self )
ENDIF
Code: Select all
Warning: It is very unlikely that you will ever need this function. If you have a widget that changes its content dynamically, it is far easier to use QStackedWidget.
Code: Select all
First it sends the widget a QCloseEvent. The widget is hidden if it accepts the close event.
Code: Select all
oStd:Activate()
msginfo( "button1click about to return" )
oStd:Release()
Code: Select all
METHOD Release class WINDOW
IF ::nType == WND_MODAL
::oEventLoop:Exit( 0 )
ENDIF
Super:Release() // it calls :close()
RETURN NIL
Code: Select all
IF ::nType != WND_MAIN
::oEventLoop:Exit( 0 )
ENDIF