QProgressDialog setCancelButton

451 views
Skip to first unread message

Luigi Ferraris

unread,
Jun 15, 2013, 9:49:12 AM6/15/13
to qtcon...@googlegroups.com
Hi Pritpal

I need to disable cancelButton on a QProgressDialog, so I follow this from Qt 4 docs:

void QProgressDialog::setCancelButton ( QPushButton * cancelButton )

Sets the cancel button to the push button, cancelButton. The progress dialog takes ownership of this button which will be deleted when necessary, so do not pass the address of an object that is on the stack, i.e. use new() to create the button. If 0 is passed then no cancel button will be shown.

But if I use :setCancelButton( 0 ) I receive "argument error".

I'm working with Qt 4.8.4

Cheers

Luigi Ferraris

Pritpal Bedi

unread,
Jun 16, 2013, 11:17:36 AM6/16/13
to qtcon...@googlegroups.com
Luigi


I need to disable cancelButton on a QProgressDialog, so I follow this from Qt 4 docs:

void QProgressDialog::setCancelButton ( QPushButton * cancelButton )


Ok.

 

Sets the cancel button to the push button, cancelButton. The progress dialog takes ownership of this button which will be deleted when necessary, so do not pass the address of an object that is on the stack, i.e. use new() to create the button. If 0 is passed then no cancel button will be shown.

But if I use :setCancelButton( 0 ) I receive "argument error".



You probably need to study Qt documentation and grasp what "0" means in C++ level.  

void QProgressDialog::setCancelButton ( QPushButton * cancelButton )


<cancelButton> should be a NULL pointer, which is denoted by "0", in documentation,
and because Qt is explained at C++ level, NULL == 0 is taken care by the compiler.
So from PRG layer you cannot pass 0 to QPushButton.

Try like, 

oDlg:setCancelButton ( QPushButton() )

Not sure it will work as expected, but then we have only this mechanism for a NULL object.


Pritpal Bedi

Luigi Ferraris

unread,
Jun 18, 2013, 4:45:15 AM6/18/13
to qtcon...@googlegroups.com
Il 16/06/2013 17.17, Pritpal Bedi ha scritto:
You probably need to study Qt documentation and grasp what "0" means in C++ level.  

void QProgressDialog::setCancelButton ( QPushButton * cancelButton )


<cancelButton> should be a NULL pointer, which is denoted by "0", in documentation,
and because Qt is explained at C++ level, NULL == 0 is taken care by the compiler.
So from PRG layer you cannot pass 0 to QPushButton.
Probably, before I need to know C++ :)). This is the most important problem for me.


Try like, 

oDlg:setCancelButton ( QPushButton() )

Not sure it will work as expected, but then we have only this mechanism for a NULL object.


I just have done a test, but cancelbutton always stay on without "text". Is not a valid solution.....
Pritpal Bedi
Many thanks for infos.

Cheers

Luigi Ferraris

Pritpal Bedi

unread,
Jun 18, 2013, 2:52:14 PM6/18/13
to qtcon...@googlegroups.com, luigfe...@gmail.com
Hi


Probably, before I need to know C++ :)). This is the most important problem for me.

May be, may not be, depends.
I just clarified you a point.
 

Try like, 

oDlg:setCancelButton ( QPushButton() )

Not sure it will work as expected, but then we have only this mechanism for a NULL object.


I just have done a test, but cancelbutton always stay on without "text". Is not a valid solution.....


So this way it is not accepted as valid NULL object.
No other way though, sorry.


Pritpal Bedi 

Francesco Perillo

unread,
Jun 18, 2013, 3:31:11 PM6/18/13
to qtcontribs
So this way it is not accepted as valid NULL object.
No other way though, sorry.


Well, there *are* several things that Luigi can do... depending on how much time he wants to apply....

1) create a c++ class inherited from QProgressDialog and add a new method that calls ... look at .qth in our project... So a SetNoCancelButton prg level method actually calls setCancelButton( NULL ) at c++ level.

2) create a qth subclass adding a line in qth:
void setCancelButton ( int nValue )

Obviously number 2 is really dangerous if a value != 0 is passed.



Then we may start to expand .qth syntax to handle NULL parameters...
void setCancelButton ( QPushButton * cancelButton ) /* N1 */
with N1 means that parameter 1 can be NULL. Of course there is a difference between NULL and parameter not present, and the fact that NIL and 0 are different harbour values... but we may decide that (integer) 0 must be used in these cases.

There are several other cases where we need this kind of object checking but this is the first one where the object ownership passes to the parent and is not destroyed... setCancelButton ( QPushButton() ) trick doesn't work in this case....

Francesco

Luigi Ferraris

unread,
Jun 19, 2013, 9:05:53 AM6/19/13
to qtcon...@googlegroups.com
Many thanks Pritpal and Francesco fro your patient :)

Il 18/06/2013 21.31, Francesco Perillo ha scritto:
> Well, there *are* several things that Luigi can do... depending on how
> much time he wants to apply....
>
> 1) create a c++ class inherited from QProgressDialog and add a new
> method that calls ... look at .qth in our project... So a
> SetNoCancelButton prg level method actually calls setCancelButton(
> NULL ) at c++ level.
>
I think this solution can be "dangerous" because can be considered out
of Qt methods.... is a specialized HbQt. I will try to do "experience" :))
> 2) create a qth subclass adding a line in qth:
> void setCancelButton ( int nValue )
>
> Obviously number 2 is really dangerous if a value != 0 is passed.
>
I think this can be considered more aligned with Qt... on the other hand
I remember other situation about 0 (see Francesco's lines below and I'm
in agreement to have a rule: integer 0 must....)
Anyway I take a look to QProgressDialog.qth (remember I'm not a C++
programmer) and I see: void setCancelButton ( QPushButton * cancelButton ).
Is there a way to write something like this (using clipper)
METHOD setCancelButton( xValue )
IF hb_IsNumeric( xValue ) .AND. xValue == 0
setCancelButton( NULL) <<< c++ level
ELSE
cancelButton := xValue I don't know if "*" means pointer to
cancelButton
ENDIF

I will investigate using Francesco's suggestions :))
>
>
> Then we may start to expand .qth syntax to handle NULL parameters...
> void setCancelButton ( QPushButton * cancelButton ) /* N1 */
> with N1 means that parameter 1 can be NULL. Of course there is a
> difference between NULL and parameter not present, and the fact that
> NIL and 0 are different harbour values... but we may decide that
> (integer) 0 must be used in these cases.
>
> There are several other cases where we need this kind of object
> checking but this is the first one where the object ownership passes
> to the parent and is not destroyed... setCancelButton ( QPushButton()
> ) trick doesn't work in this case....
>
> Francesco

Luigi

Pritpal Bedi

unread,
Jun 19, 2013, 9:21:49 PM6/19/13
to qtcon...@googlegroups.com, luigfe...@gmail.com
Luigi


You can do like ( not tested but should work ):


oDlg := QProgressDialog()
oBtn := QPushButton()

oDlg:setCancelButton( oBtn )
oBtn:hide()


And let me know it it worked...


Pritpal Bedi 

Luigi Ferraris

unread,
Jun 22, 2013, 8:36:30 AM6/22/13
to Pritpal Bedi, qtcon...@googlegroups.com
We had the same idea :) ....
and yes it works!

Many thanks for your help

Cheers

Luigi Ferraris

Reply all
Reply to author
Forward
0 new messages