Results 1 to 3 of 3

Thread: QT: Create new connections when signal is emitted

  1. #1

    Default QT: Create new connections when signal is emitted

    Hello, I would like to create a SLOT that establish some connections between classes. Something like this:

    Qt Code:
    1. void MainWindow::onDocumentDockletUndocked( bool isFloating )
    2. {
    3. if(isFloating) {
    4. foreach(MultiEditor * me, mEditorList) {
    5. connect(me, SIGNAL(currentDocumentChanged(Document*)),
    6. mDocumentsDocklet, SLOT(setCurrent(Document*)));
    7. }
    8. } else {
    9. foreach(MultiEditor * me, mEditorList) {
    10. disconnect(me, SIGNAL(currentDocumentChanged(Document*)),
    11. mDocumentsDocklet, SLOT(setCurrent(Document*)));
    12. }
    13. }
    14. }
    To copy to clipboard, switch view to plain text mode 

    This specific example isn't working (though the same works perfectly in a different context).
    So I was wondering: can I established or remove connections on the fly as above?

  2. #2
    Join Date
    Jan 2008
    Alameda, CA, USA
    Thanked 808 Times in 797 Posts
    Qt products
    Windows Android

    Default Re: QT: Create new connections when signal is emitted

    Nothing wrong with that code as far as I can see. Do the member variables actually have the values you think they should?
    Last edited by d_stranz; 5th February 2017 at 17:51.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3

    Default Re: QT: Create new connections when signal is emitted

    d_stranz! You are great (and right)!
    mDocumentDocklet is (slightly) the wrong class, as I need a subclass. Thanks!

Similar Threads

  1. readyRead signal is not emitted
    By gig-raf in forum Qt Programming
    Replies: 2
    Last Post: 16th February 2016, 08:13
  2. Signal can't be emitted !
    By Vladimir_ in forum Newbie
    Replies: 32
    Last Post: 27th September 2014, 20:31
  3. Signal isn't emitted from socket
    By 8Observer8 in forum Newbie
    Replies: 3
    Last Post: 14th August 2013, 13:33
  4. signal emitted when I zoom
    By mastupristi in forum Qwt
    Replies: 1
    Last Post: 8th July 2009, 17:02
  5. Signal emitted more than once?
    By dbrmik in forum Qt Programming
    Replies: 3
    Last Post: 13th March 2009, 12:44

Tags for this Thread


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.