Results 1 to 2 of 2

Thread: qt 4.3.4: bind "connect" slot action at runtime

  1. #1
    Join Date
    Aug 2008
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default qt 4.3.4: bind "connect" slot action at runtime

    Hello,

    how can I connect

    Qt Code:
    1. connect(exitAct, SIGNAL(triggered()), qApp, SLOT(closeAllWindows()));
    To copy to clipboard, switch view to plain text mode 

    at runtime (closeAllWindows) ?

    thanks for helping

    Jens



    Qt Code:
    1. QObject::connect(
    2. kawin[win]->btn[kawin[win]->PushButtonCount-1], // the button
    3. SIGNAL(clicked()), // the signal
    4. kawin[win], // the window/widget
    5. SIGNAL(kawin[win]->btn[kawin[win]->PushButtonCount-1]->buttonClicked())
    6. );
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 25th August 2008 at 14:52. Reason: missing [code] tags

  2. #2
    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: qt 4.3.4: bind "connect" slot action at runtime

    Quote Originally Posted by paule22 View Post
    how can I connect

    connect(exitAct, SIGNAL(triggered()), qApp, SLOT(closeAllWindows()));

    at runtime (closeAllWindows) ?
    All connections are established at the runtime.

    Quote Originally Posted by paule22 View Post
    QObject::connect(
    kawin[win]->btn[kawin[win]->PushButtonCount-1], // the button
    SIGNAL(clicked()), // the signal
    kawin[win], // the window/widget
    SIGNAL(kawin[win]->btn[kawin[win]->PushButtonCount-1]->buttonClicked())
    );
    You have to pass a string literal to SIGNAL() and SLOT() macros. If you want to determine what to connect to at runtime, you can't use these macros. Luckily they have very simple definitions:
    Qt Code:
    1. #define SLOT(a) "1"#a
    2. #define SIGNAL(a) "2"#a
    To copy to clipboard, switch view to plain text mode 
    But do you really don't know the name of the destination slot/signal a priori?


    Also take a look at QSignalMapper and QButtonGroup classes.

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.