QgridLayout addItem

51 views
Skip to first unread message

Luigi Ferraris

unread,
Jun 16, 2016, 9:38:53 AM6/16/16
to QtContribs
Hi Pritpal,
I'm using QGridLayout; somewhere I see this C++ code: glayout->addItem(new QSpacerItem(250, 0), 0, 4);
So, I have used this code with HbQt but I get a crash: argument error.

I looked to the QGridLayout.cpp and I see everywhere if( hbqt_par_isDerivedFrom( 1, "QLAYOUTITEM" )
On Qt docs, I have read
void QGridLayout::addItem( QLayoutItem *item....

It's seems HbQt code is aligned (object must be derived from...) but QSpacerItem is derived from QLayoutItem so I don't know why I get an error.

Regards
Luigi Ferraris

Pritpal Bedi

unread,
Jun 16, 2016, 2:53:33 PM6/16/16
to QtContribs
Strange.

Show me prg code how you are using this construct.


Pritpal Bedi 

Luigi Ferraris

unread,
Jun 17, 2016, 4:25:11 AM6/17/16
to QtContribs
Hi Pritpal,
yes it's very strange because I have already used with QVboxLayout and works fine.

Anyway, today I have rebuilt the program (removed the working directory -.cpp, .o, .c, etc.) and works fine; I have played with several parameters and never got a crash. Very strange.

This is the snippet code; remember: I'm using HQL layer (class inheritance), for this reason you will see objects/methods start with HQL prefix. L3W prefix are my facilities.
A little brief: on this form there are 6 widtges on 3 rows; every row has a hqlLabel (QLabel) and an input field (hqlInputText(), hqlInputNumeric(), but they are QLineEdit) then it has a hqlToolBar (QToolbar). The form has a central widget (hqlWidget is QWidget) with a layout (hqlGridLayout or QGridLayout)
 
  WITH OBJECT ::oWindow := hqlChildWindow( NIL, ::parentWindow() )
      :setAttribute( Qt_WA_DeleteOnClose )
      :setMinimumSize( l3wSys:get( "Form:MinQSize" ) )
      :setCentralWidget( hqlWidget( NIL, ::oWindow ) )
      :setGeometry( :style:alignedRect( Qt_LeftToRight, Qt_AlignCenter, :size(), :parentWidget:geometry() ) )
      :hqlSetIcon( ":pgmico" )
      :hqlCaption := cTitle
      :hqlOnActivate( { || ::__onActivate() } )
      :hqlOnClose( { || ::__onClose() } )

      WITH OBJECT hqlToolBar()
         :setIconSize( l3wSys:get( "BarButQSize" ) )
         :hqlClosable := .F.
         :hqlAddButton( NIL, NIL, { || ::oWindow:hqlRelease() }, L3wSys:get("Button:Exit_Icon"), hqlTran( "l3wmtrn", L3wSys:get("Button:Exit_ToolTip")), NIL, NIL, .F., .T. )
         :hqlAddButton( "btsave", NIL, { || ::__saveRecord() }, L3wSys:get("Button:RecSave_Icon"), hqlTran( "l3wmtrn", L3wSys:get("Button:RecSave_ToolTip")), NIL, NIL, .F., .F. )
      END WITH

      WITH OBJECT :centralWidget()
     
         :setLayout( hqlGridLayout() )

         WITH OBJECT hqlLabel()
            :hqlAddMeToLayout( :parent:layout(), 0, 0 )
            :setAlignment( hb_BitOr( Qt_AlignRight, Qt_AlignVCenter ) )
            :hqlCaption := hqlTran( "thisapp", "Code" )
         END WITH
         WITH OBJECT hqlInputText( "prgcodice" )
            :hqlAddMeToLayout( :parent:layout(), 0, 1 )
            :setSizePolicy( QSizePolicy_Maximum, QSizePolicy_Maximum )
            :setPlaceholderText( hqlTran( "thisapp", "a valid code" ) )
            :hqlInputMask( ::oModelData:prgcodice:inputMask() )
            :hqlValid( { || ::__Valid_prgcodice() } )
            :hqlOnTabPressed( { || ::__tryToManage() } )
         END WITH

         :layout:addItem( QSpacerItem( 0, 0, QSizePolicy_Minimum, QSizePolicy_Maximum ), 1, 0, 0, 3, Qt_AlignCenter )

         WITH OBJECT hqlLabel()
            :hqlAddMeToLayout( :parent:layout(), 2, 0 )
            :setAlignment( hb_BitOr( Qt_AlignRight, Qt_AlignVCenter ) )
            :hqlCaption := hqlTran( "thisapp", "Description" )
         END WITH
         WITH OBJECT hqlInputText( "prgdescri" )
            :hqlAddMeToLayout( :parent:layout(), 2, 1 )
            :setSizePolicy( QSizePolicy_Maximum, QSizePolicy_Maximum )
            :setMinimumWidth( 200 )
            :setMaxLength( ::oModelData:prgdescri:Length() )
            :hqlValid( { || ::__Valid_prgdescri() } )
            :hqlEnabled( .F. )
         END WITH

         :layout:addItem( QSpacerItem( 0, 0, QSizePolicy_Minimum, QSizePolicy_Maximum ), 3, 0, 0, 3, Qt_AlignCenter )

         WITH OBJECT hqlLabel()
            :hqlAddMeToLayout( :parent:layout(), 4, 0 )
            :setAlignment( hb_BitOr( Qt_AlignRight, Qt_AlignVCenter ) )
            :hqlCaption := hqlTran( "thisapp", "Value" )
         END WITH
         WITH OBJECT hqlInputNumeric( "prgnumero" )
            :hqlAddMeToLayout( :parent:layout(), 4, 1 )
            :setSizePolicy( QSizePolicy_Maximum, QSizePolicy_Maximum )
            :hqlValid( { || ::__Valid_prgnumero() } )
            :hqlInputMask( ::oModelData:prgnumero:inputMask() )
            :hqlEnabled( .F. )
         END WITH

I have bolded the code but as I wrote, now works fine after rebuilding the program. I not able to replicate previous error: I don't know.

I will continue to investigate with different parameters.
I'm sorry to waste your time.
Luigi
Reply all
Reply to author
Forward
0 new messages