Main and no-main windows type

Moderator: Rathinagiri

Post Reply
User avatar
concentra
Posts: 256
Joined: Fri Nov 26, 2010 11:31 am
Location: Piracicaba - Brasil

Main and no-main windows type

Post by concentra » Fri Jun 10, 2011 11:03 am

There are some mess in windows types in HMG4.
At first, one can write a program that have 2 ( or more ) WND_MAIN windows, invoking ::s_qApp:exec() 2 ( or more ) times and this causes the application to close when the last WND_MAIN window is released. And its possibly that there are other consequences in invoking ::s_qApp:exec() more than one time...
See:

Code: Select all

#include "hmg.ch"

FUNCTION Main()

   LOCAL oMainWindow
   LOCAL oButton1
   LOCAL oButton2

   HbQt_ErrorSys()

   WITH OBJECT oMainWindow := Window():New()
      :Width  := 200
      :Height := 400
      :Title  := "Tests"
      :Type   := WND_MAIN
      :OnInit := {|| oMainWindow:Center()}

      WITH OBJECT oButton1 := Button():New()
         :Row     := 40
         :Col     := 10
         :Width   := 180
         :Caption := 'Click to Open Child Window'
         :OnClick := { || ChildWindow() }
      END WITH

   End   // oMainWindow

   oMainWindow:Activate()

   RETURN




FUNCTION ChildWindow()

   LOCAL oChildWindow
   LOCAL oButton3

   WITH OBJECT oChildWindow := Window():New()
      :Width  := 400
      :Height := 300
      :Title  := "Child Window"
      :Type   := WND_MAIN
      :OnInit := { || oChildWindow:Center() }

      WITH OBJECT oButton3 := Button():New()
         :Row     := 40
         :Col     := 10
         :Width   := 380
         :Caption := 'Click to Close Child Window'
         :OnClick := { || oChildWindow:Release() }
      END WITH

   End   // oChildWindow

   oChildWindow:Activate()

RETURN NIL
Other one is that if a window is defined other type than WND_MAIN or WND_MODAL, the second window uses the first one loop while running, with sometimes weird results.
Try this:

Code: Select all

#include "hmg.ch"

FUNCTION Main()

   LOCAL oMainWindow
   LOCAL oButton1
   LOCAL oButton2

   HbQt_ErrorSys()

   WITH OBJECT oMainWindow := Window():New()
      :Width  := 200
      :Height := 400
      :Title  := "Tests"
      :Type   := WND_MAIN
      :OnInit := {|| oMainWindow:Center()}

      WITH OBJECT oButton1 := Button():New()
         :Row     := 40
         :Col     := 10
         :Width   := 180
         :Caption := 'Click to Open Child Window'
         :OnClick := { || ChildWindow() }
      END WITH

   End   // oMainWindow

   oMainWindow:Activate()

   oMainWindow := NIL

   RETURN




FUNCTION ChildWindow()

   LOCAL oChildWindow
   LOCAL oButton3

   WITH OBJECT oChildWindow := Window():New()
      :Width  := 400
      :Height := 300
      :Title  := "Child Window"
      :Type   := WND_STANDARD
      :OnInit := { || oChildWindow:Center() }

      WITH OBJECT oButton3 := Button():New()
         :Row     := 40
         :Col     := 10
         :Width   := 380
         :Caption := 'Click to Close Child Window'
         :OnClick := { || oChildWindow:Release() }
      END WITH

   End   // oChildWindow

   oChildWindow:Activate()

   oChildWindow := NIL

RETURN NIL
In this,

Code: Select all

oChildWindow:Activate()
Don´t have its own loop and will continue to the next line

Code: Select all

oChildWindow := NIL
The second window is painted, but when the button is clicked oChildWindow isn´t in memory anymore, causing an error.
Someone can ask "Why oChildWindow := NIL ?" and the answer is to release the memory used by controls not needed anymore.

This two problems can be fixed if only one WND_MAIN is allowed, forcing the first one to be the WND_MAIN and any subsequent ones other types, even if defined as WND_MAIN.
And generating a loop in every type, not only WND_MAIN and WND_MODAL.

I will change window.prg this way, if someone have any comment, please do.
[[]] Mauricio Ventura Faria

Carlos Britos
Posts: 220
Joined: Sat Aug 02, 2008 5:03 pm
Has thanked: 6 times
Been thanked: 2 times

Post by Carlos Britos » Fri Jun 10, 2011 6:08 pm

concentra wrote:There are some mess in windows types in HMG4.
At first, one can write a program that have 2 ( or more ) WND_MAIN windows, invoking ::s_qApp:exec() 2 ( or more ) times and this causes the application to close when the last WND_MAIN window is released. And its possibly that there are other consequences in invoking ::s_qApp:exec() more than one time...
Hi Mauricio
I´m agree.
Another thing that we have to fix is the duplicity of windows/control names.
I've tried with an array at the application class to Un/Register names, but is not simple to keep it updated, creating / releasing controls.
Regards/Saludos, Carlos (bcd12a)

User avatar
l3whmg
Posts: 694
Joined: Mon Feb 23, 2009 8:46 pm
Location: Italy
Contact:

Post by l3whmg » Sat Jun 11, 2011 4:35 pm

I Mauricio,
I'm in agreement with you and I want remember that, in HMG3, can be only one MAIN WINDOW. The other must be CHILD or STANDARD or MODAL.
Your example is: right about HMG4 syntax but wrong in HMGx philosopy. Type must be WND_CHILD

Code: Select all

   WITH OBJECT oChildWindow := Window():New()
      :Width  := 400
      :Height := 300
      :Title  := "Child Window"
      :Type   := WND_MAIN
      :OnInit := { || oChildWindow:Center() }
So we must be checked if WND_MAIN it's already defined.
About loop for everyone... With Modal it's necessary, but with WND_MAIN i have :?:

Best regards
Luigi from Italy
www.L3W.it

User avatar
Rathinagiri
Posts: 5250
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 167 times
Been thanked: 165 times
Contact:

Post by Rathinagiri » Sat Jun 11, 2011 4:56 pm

Rightly said Luigi.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

User avatar
concentra
Posts: 256
Joined: Fri Nov 26, 2010 11:31 am
Location: Piracicaba - Brasil

Post by concentra » Tue Jun 14, 2011 11:39 am

Hi Luigi !
l3whmg wrote:Your example is: right about HMG4 syntax but wrong in HMGx philosopy. Type must be WND_CHILD
I know that, that was just a sample on what could happen.
So we must be checked if WND_MAIN it's already defined.
Done and commited.
About loop for everyone... With Modal it's necessary, but with WND_MAIN i have :?:
Ok, what I said is that the main window event loop is the ::s_qApp:exec() itself and all other window types the QEventLoop().
Other thing I realized is that HMG4 don´t have 'dialogs', only 'windows'. Windows are more complex types and not needed all time. I will implement QT dialogs in a class, they are simpler and can be used for simple tasks.
[[]] Mauricio Ventura Faria

Post Reply