Results 1 to 4 of 4

Thread: little logical question........

  1. #1
    Join Date
    Nov 2007
    Posts
    42
    Thanks
    11
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question little logical question........

    Hi

    i had connected about 15 QActions to a common SLOT, but i am not able to find in my slot function from which QAction the SIGNAL is coming . I had coded something like this

    Qt Code:
    1. for(int i=0; i<15; i++)
    2. {
    3. play_add_Act[i] = new QAction(this);
    4. play_add_Act[i]->setText("Play list");
    5. connect(play_add_Act[i], SIGNAL(triggered()), this, SLOT(addplaylist()));
    6. }
    To copy to clipboard, switch view to plain text mode 

    i also tried to pass index variable in slot function, but Wysota said that we shouldn't pass parameters names or values in SIGNAL or SLOT macros

    so how can i identify signal sender action??????
    Last edited by jpn; 12th May 2008 at 14:29. Reason: missing [code] tags

  2. #2
    Join Date
    Nov 2007
    Posts
    42
    Thanks
    11
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: little logical question........

    how can i pass signal emitting object as a parameter in SLOT macro so i can easily access slot function

    (is it possible like this )

    Qt Code:
    1. connect(play_add_Act[0], SIGNAL(triggered()), this, SLOT(addplaylist(QAction *play_add_Act[0])));
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 12th May 2008 at 14:29. Reason: missing [code] tags

  3. #3
    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: little logical question........

    You can try one of two things. Either use QObject::sender() to determine which action sent the signal or use QSignalMapper to identify the sending action using a number or string.

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

    sudheer (8th May 2008)

  5. #4
    Join Date
    Nov 2007
    Posts
    42
    Thanks
    11
    Qt products
    Qt4
    Platforms
    Unix/X11

    Smile Re: little logical question........

    thank q sir

    hey guys whoever uses a single slot to a no' of connections it will be very very useful

    see the syntax of it
    Qt Code:
    1. QAction *action = qobject_cast<QAction *>(sender());
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 12th May 2008 at 14:29. Reason: missing [code] tags

Similar Threads

  1. SQL Question
    By ^NyAw^ in forum Qt Programming
    Replies: 5
    Last Post: 8th April 2008, 20:36
  2. Replies: 1
    Last Post: 15th March 2007, 21:45
  3. Question regarding how to paint after zoom.
    By JonathanForQT4 in forum Qt Programming
    Replies: 2
    Last Post: 26th January 2007, 16:34
  4. QThread exit()/quit() question
    By TheKedge in forum Qt Programming
    Replies: 1
    Last Post: 28th August 2006, 15:38

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.