QDialogButtonBox connecting with function

1,895 views
Skip to first unread message

dor...@sezampro.rs

unread,
Aug 27, 2014, 2:37:54 PM8/27/14
to qtcon...@googlegroups.com
Hi !
 
Can I use QDialogButtonBox in Harbour ?
 
Using QT Designer I created dialog windows with several widgets and one buttonBox containing two standard buttons Ok and Cancel.
 
I tried to connect function with either buttons Ok and Cancel but no success. I used oWnd:buttonBox:Cancel:connect ("clicked()", { || Fcncl () }).
 
Also tried some other syntax variants with no result.
 
It seems I do not know proper syntax for connecting buttonBox standard buttons with my function.
 
Can anyone help me ?
 
Regards,
 
Dordije.
 
 

Pritpal Bedi

unread,
Aug 27, 2014, 2:52:11 PM8/27/14
to qtcon...@googlegroups.com
Hi


I tried to connect function with either buttons Ok and Cancel but no success. I used

 
oWnd:buttonBox:Cancel:connect ("clicked()", { || Fcncl () }).


oWnd:buttonBox is a container only.
HbQt addresses the controls directly without its parent reference.
So, suppose the cancel button has this name (check in your .ui), 
   pushButtonCancel
Then access it as 
   oWnd:pushButtonCancel


Pritpal Bedi
a student of software analysis & concepts

Dordije

unread,
Aug 27, 2014, 3:17:25 PM8/27/14
to qtcon...@googlegroups.com
 
Hi Pritpal,
I tried with direct referencing button but no success. Standard buttons in button box do not have attribute “name”.
This is part of my ui file:
 
<widget class="QDialogButtonBox" name="buttonBox">
<property name="geometry">
  <rect>
   <x>240</x>
   <y>660</y>
   <width>341</width>
   <height>32</height>
  </rect>
</property>
<property name="orientation">
  <enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
  <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
 
This widget is inside widget of QDialog class (in my code it is oWnd).
 
I tried with oWnd:Cancel:connect ("clicked()", { || Fcncl () }). Is this proper syntax in my case ?
 
In Qt documentation I found this:
 
void QDialogButtonBox::clicked ( QAbstractButton * button ) [signal]

This signal is emitted when a button inside the button box is clicked. The specific button that was pressed is specified by button.

In clicked slot I must specify  QAbstractButton * button  but how ? 
 
Regards,
 
Dordije.
 

Pritpal Bedi

unread,
Aug 27, 2014, 3:36:48 PM8/27/14
to qtcon...@googlegroups.com
Hi Dordije


 
In Qt documentation I found this:
 
void QDialogButtonBox::clicked ( QAbstractButton * button ) [signal]

This signal is emitted when a button inside the button box is clicked. The specific button that was pressed is specified by button.

In clicked slot I must specify  QAbstractButton * button  but how ? 


Ah OK.

oWnd:oDialogButtonBox:connect( "clicked(QAbstractButton*)", { |oButton|  ManageButton( oButton ) } )

then based on the text of oButton take appropriate action.

Alternatively:

Do not use QDialogButtonBox(). Instead have a QGroupBox containing 
two push buttons, <Cancel> and <OK>, name them as you wish and access from 
.prg code.

Dordije

unread,
Aug 28, 2014, 4:53:45 AM8/28/14
to qtcon...@googlegroups.com
 
Hi Pritpal,
sorry I am late with answer  because I needed to try your suggestions.
 
First I started with oWnd:oDialogButtonBox:connect( "clicked(QAbstractButton*)", { |oButton|  ManageButton( oButton ) } ) command.
Program was aware of ManageButton function.
In ManageButton function I did test what button is clicked with IF oButton==QDialogButton_Ok. But whenever I click on either of standard buttons I got Windows error that say “TESTGUI.EXE stops execution ...” and execution crashed.
In hb_out.log I can see that it is something concerning QDIALOG:EXEC with Application Internal Error, Unrecoverable error 6005 message. Also reported big list of modules from \Windows\System32 folder.
 
Even without testing (in ManageButton function I only have some MsgInfo(“...”) command ), again I got stop execution error.
 
So I decided to try QGroupBox as you suggested. That worked well for me. I can control OK and Cancel buttons in proper way.
 
Later these days I will again try with QDialogButtonBox creating some other simplier example. If I succeed will report what I did.
 
Thank you for your time.
 
Regards,
 
Dordije.
 
 
 

Pritpal Bedi

unread,
Aug 28, 2014, 3:03:52 PM8/28/14
to qtcon...@googlegroups.com
Hi


First I started with oWnd:oDialogButtonBox:connect( "clicked(QAbstractButton*)", { |oButton|  ManageButton( oButton ) } ) command.
Program was aware of ManageButton function.
In ManageButton function I did test what button is clicked with IF oButton==QDialogButton_Ok. But whenever I click on either of standard buttons I got Windows error that say “TESTGUI.EXE stops execution ...” and execution crashed.

And here you are making a big mistake.
oButton is of type QAbstractButton and you are comparing it with a NUMERIC, how come ?

Dordije

unread,
Aug 29, 2014, 11:10:35 AM8/29/14
to qtcon...@googlegroups.com
Hi Pritpal !
 
// And here you are making a big mistake.
// oButton is of type QAbstractButton and you are comparing it with a NUMERIC, how come ?
 
In some examples on Internet I found that can test clicked button with:

................

void CProgOptions::on_buttonBox_clicked(QAbstractButton *button)
{
    if(button== buttonBox->button(QDialogButtonBox::Reset) )

   {
         HERE GOES SOME CODE
    }
}

..............

 

According to this in ManageButtons I did button test with

 

IF oButton==buttonBox:button(QDialogButton_Ok)

 

but with same crashing (precisely, message is “TESTGUI.EXE has stopped working”).

 

Some examples on Internet suggested to try with:

 

IF buttonBox:standardButton(oButton)==QDialogButtonBox_Apply    or with

 

IF buttonBox:buttonRole(oButton)==QDialogButtonBox_AcceptRole

 

In all my tries program crashes.  When I do not use clicked slot, program do not crash.

 

I am aware that I do not have enough knowledge about HbQt.

 

Please, can you tell me what do I must read to learn wrapper functions for QT in Harbour.

 

Now I use QGroupBox instead QdialogButtonBox.

 

Regards,

 

Dordije.
 
 

Pritpal Bedi

unread,
Aug 29, 2014, 11:52:01 AM8/29/14
to qtcon...@googlegroups.com
Hi Dorgie


void CProgOptions::on_buttonBox_clicked(QAbstractButton *button)
{
    if(button== buttonBox->button(QDialogButtonBox::Reset) )

   {
         HERE GOES SOME CODE
    }
}



Comparison like this is not possible in HbQt as class object holding 
the Qt object is constructed new every first call.  C++ does right any way.


IF oButton==buttonBox:button(QDialogButton_Ok)



As above.

 IF buttonBox:standardButton(oButton)==QDialogButtonBox_Apply    or with

 

IF buttonBox:buttonRole(oButton)==QDialogButtonBox_AcceptRole



The above call should be ok, but if not, then seems some Qt bug.
 

Please, can you tell me what do I must read to learn wrapper functions for QT in Harbour.


You are already looking at right places.
  

Now I use QGroupBox instead QdialogButtonBox.



When you do not find correct usage via some object it is always safe to look for work-arounds.

Luigi Ferraris

unread,
Jun 10, 2017, 1:51:03 PM6/10/17
to QtContribs
Hi Pritpal,
I jump on this old post because I have the same problem: program crash creating hb_out.log

Here snipped code:
oDlgButtonBox:connect( "clicked(QAbstractButton*)", { |o| udfClickedBut(o) } )

STATIC PROCEDURE udfClickedBut(o)
   hb_trace( HB_TR_ALWAYS, o:className() + " clicked" )
RETURN


where oDlgButtonBox is QDialogButtonBox with three standards button: QDialogButtonBox_Ok, QDialogButtonBox_Cancel, QDialogButtonBox_Help

all other QDialogButtonBox signals work fine.

Regards
Ferraris Luigi
Reply all
Reply to author
Forward
0 new messages