Results 1 to 7 of 7

Thread: surprise why this simple statement doesnt work

  1. #1
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default surprise why this simple statement doesnt work

    Hi,
    I want to disable my button on the click of it ...so i wrote this but it doesnt seem to work...
    Qt Code:
    1. connect(navigate->recordButton,SIGNAL(clicked()),this,SLOT(setDisabled(TRUE)));
    To copy to clipboard, switch view to plain text mode 
    i am surprised ..why ?

  2. #2
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: surprise why this simple statement doesnt work

    arghh...i was using 'this' in the connect..my bad...

  3. #3
    Join Date
    Jul 2006
    Location
    Catalunya - Spain
    Posts
    117
    Thanks
    16
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: surprise why this simple statement doesnt work

    Quote Originally Posted by salmanmanekia View Post
    Hi,
    I want to disable my button on the click of it ...so i wrote this but it doesnt seem to work...
    Qt Code:
    1. connect(navigate->recordButton,SIGNAL(clicked()),this,SLOT(setDisabled(TRUE)));
    To copy to clipboard, switch view to plain text mode 
    i am surprised ..why ?
    Didn't you receive an strange message when executing from Qt saying "cannot find SLOT setDisabled(TRUE)" ?

    It may never work. Signal & Slot must have the same signature. Of course, these two methods have the same, but doesn't mean the same ( if is clicked but is not checked, setDisabled doesn't work as you want )

    You can derive the QAbstractButton class, creating a new SLOT disableWhenPress ( bool Ignore ) and connect it like this :

    connect(navigate->recordButton,SIGNAL(clicked()),this,SLOT(disableW henPress()));

    And it may work...

    Another way of achieving this, perhaps a simpler one, could be connecting the pressed signal to an slot that does some stuff ( if you press the button to take some action, you have to program that action, haven't you ? ) and on the first line you disable the button manually :

    button->setDisabled(true)

  4. #4
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: surprise why this simple statement doesnt work

    Didn't you receive an strange message when executing from Qt saying "cannot find SLOT setDisabled(TRUE)" ?
    no, and i shouldnt be recieving this message because there is a slot named setDisabled in QWidget .http://doc.trolltech.com/4.4/qwidget.html#setDisabled

    Of course, these two methods have the same, but doesn't mean the same ( if is clicked but is not checked, setDisabled doesn't work as you want )
    i didnt understand what do you mean by that..

    connect(navigate->recordButton,SIGNAL(clicked()),this,SLOT(disableW henPress()));
    I had already tried this way but this also did not worked..

    Another way of achieving this, perhaps a simpler one, could be connecting the pressed signal to an slot that does some stuff ( if you press the button to take some action, you have to program that action, haven't you ? ) and on the first line you disable the button manually :
    button->setDisabled(true)
    This is very true but on the pressing of my button i am calling a different widget while as far button itself is concerned it is in a different widget ,so it is not true for my case....
    THanks

  5. #5
    Join Date
    Jul 2006
    Location
    Catalunya - Spain
    Posts
    117
    Thanks
    16
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: surprise why this simple statement doesnt work

    Quote Originally Posted by salmanmanekia View Post
    no, and i shouldnt be recieving this message because there is a slot named setDisabled in QWidget
    First I've to say sorry. I've wrote my answer while you write you answered yourself and I didn't see the difference you said ( I mean the "this" error )

    i didnt understand what do you mean by that..
    I think I haven't explained it very clear ( I don't speak/write English usually and perhaps that's the problem ).

    I want to say that connecting a signal with an slot both with the same "aspect" ( both take a boolean parameter ) is possible, but the meaning of that value perhaps is not the desired or expected.

    And of course I didn't know that you can call an SLOT changing parameter's values as you do. I thought that was an error.

    Thanks to you, as we say in Spanish "Nunca te acostarás sin saber una cosa más" ( You'll never go to bed without learning something )

  6. The following user says thank you to jpujolf for this useful post:

    salmanmanekia (28th July 2008)

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: surprise why this simple statement doesnt work

    Quote Originally Posted by jpujolf View Post
    And of course I didn't know that you can call an SLOT changing parameter's values as you do. I thought that was an error.
    It is an error. You were right, one can't specify parameter values or names in SLOT() and SIGNAL() macros.

  8. The following user says thank you to jacek for this useful post:

    salmanmanekia (28th July 2008)

  9. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: surprise why this simple statement doesnt work

    Quote Originally Posted by jacek View Post
    It is an error. You were right, one can't specify parameter values or names in SLOT() and SIGNAL() macros.
    As noted in the FAQ:

    http://www.qtcentre.org/forum/faq.ph...ot_with_values

  10. The following user says thank you to wysota for this useful post:

    salmanmanekia (28th July 2008)

Similar Threads

  1. QHttp simple program doesn't work
    By johncharlesb in forum Qt Programming
    Replies: 0
    Last Post: 4th April 2008, 04:18

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.