Results 1 to 5 of 5

Thread: Disconnect slot when another is being connected

  1. #1
    Join Date
    Jan 2009
    Posts
    14
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Question Disconnect slot when another is being connected

    Hi,
    I have a QPushButton, in a QDialog, that has its signal "clicked()" connected to one slot that is part of the Dialog.
    I want that someone, externally of this Dialog, connects to same signal then disconnects from the other slot.
    I want a QPushButton that can has only one slot connected to its signals "clicked()"
    I see this function:
    QObject::connectNotify(const char * signal)

    But notifies when the connection is already made. So if I overload this function to do something like this:
    Qt Code:
    1. void CMyButton::connectNotify(const char * signal)
    2. {
    3. this->disconnect(SIGNAL(signal));
    4. // How to connect the last signal-slot made?
    5. }
    To copy to clipboard, switch view to plain text mode 

    I disconnect all, including the last connection made that I want to keep.

    Any ideas??

    Thanks

  2. #2
    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: Disconnect slot when another is being connected

    If you want to have only one listener, it might be easier to not use signals and slots at all - just provide a "setListener()" method where you will pass a pointer to the object you want notified.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jan 2009
    Posts
    14
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Disconnect slot when another is being connected

    Yes, I'm so focused in signals/slots that I forgot the "old-ways".
    The only thing is that in all the app we're using the signal/slot mechanism I don't want to be different here.

    Thank you.

  4. #4
    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: Disconnect slot when another is being connected

    But signals and slots is a way of notifing environment of an object about changes in the object. You shouldn't assume that only one person will be listening to that. So you're breaking the signal/slot paradigm anyway.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jan 2009
    Posts
    14
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Disconnect slot when another is being connected

    You're right.
    Is too tricky/dirty and at last it will be confusing because I break the signals/slots paradigm.

    Thank you

Similar Threads

  1. How to declare SLOT as a parameter to member function?
    By QPlace in forum Qt Programming
    Replies: 2
    Last Post: 17th July 2018, 00:41
  2. Replies: 12
    Last Post: 18th September 2008, 15:04
  3. Problem When Creating my own Slot
    By Fatla in forum Qt Programming
    Replies: 12
    Last Post: 6th June 2008, 14:44
  4. Replies: 1
    Last Post: 6th March 2007, 15:27

Tags for this Thread

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.