Results 1 to 8 of 8

Thread: Many signals one slot

  1. #1
    Join Date
    Apr 2009
    Posts
    25
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Many signals one slot

    Another newbie question.

    Signals emittes from 5 pushbuttons have to be connected with one slot. But this slot must know from which pushbutton was activated. I already tried to do this:

    Qt Code:
    1. slot (int i);
    2. ...
    3. connect(push1, SIGNAL(clicked()),this, slot(1));
    To copy to clipboard, switch view to plain text mode 
    But doesn't work.
    Any suggestions?

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Many signals one slot

    Have a look at QObject::sender().
    Qt Code:
    1. MyClass::mySlot(){
    2. if (sender() == myButton1)
    3. {...}
    4. }
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to Lykurg for this useful post:

    ^Nisok^ (17th April 2009)

  4. #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: Many signals one slot

    Have a look at QSignalMapper.
    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. The following user says thank you to wysota for this useful post:

    ^Nisok^ (17th April 2009)

  6. #4
    Join Date
    Apr 2009
    Posts
    25
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Many signals one slot

    Thanks again. I used the mapping and I did it.
    But this success led me to another different problem. I will continue to this thread.
    Part of configdilog.h
    Qt Code:
    1. private:
    2. QLineEdit *ebmFloodImage,*ebmFloodImage20, *ebmCrystalEnergies, *ebmIMat, *ebmJMat;
    3. QPushButton *psbFloodImage,*psbFloodImage20, *psbCrystalEnergies, *psbIMat, *psbJMat;
    4. QString fl, fl20, ec, im, jm;
    5. private slots:
    6. void selectFile(const QString &);
    To copy to clipboard, switch view to plain text mode 

    And at the constructor I implement everything you see here. I connect the pushbuttons with the slot selectFile. But when I go to the slot and select a new file, I cannot "print" the new name to the lineEdits (from the slot routine, at the constructor I can set the Text). The following runtime error appears.

    Qt Code:
    1. Program received signal SIGSEGV, Segmentation fault.
    2. 0x00007f7a0331b6f0 in QLineEdit::setText () from /usr/lib/libQtGui.so.4
    To copy to clipboard, switch view to plain text mode 

    Do have any idea where this comes from??

  7. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Many signals one slot

    Probably you have a local variable in the constructor, instead of assigning to the member variable:
    Qt Code:
    1. Type* var = new Something;
    2. // vs.
    3. var = new Something; // <-- should be like this
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

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

    ^Nisok^ (18th April 2009)

  9. #6
    Join Date
    Apr 2009
    Posts
    25
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Many signals one slot

    Thanx, a lot! That was the problem. The statement that I had meant that I redeclare a new LineEdit and I don't use the global one?

  10. #7
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Many signals one slot

    One assigns to a new local variable, another assigns to the member variable. Member variables are not global variables.
    J-P Nurmi

  11. #8
    Join Date
    Apr 2009
    Posts
    25
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Many signals one slot

    Yes... sorry.. idiot mistake...

Similar Threads

  1. Signals are delayed on X11?
    By Cruz in forum Qt Programming
    Replies: 13
    Last Post: 18th February 2009, 12:59
  2. signals and slot...can i select my option ?
    By salmanmanekia in forum Qt Programming
    Replies: 8
    Last Post: 7th August 2008, 11:44
  3. [Basic question] Signals & Slot
    By GortiZ in forum Newbie
    Replies: 5
    Last Post: 1st April 2008, 10:39
  4. many signals, one slot
    By eric in forum Qt Programming
    Replies: 5
    Last Post: 24th January 2008, 07:25
  5. Signals and slot
    By rajeshclt3 in forum Newbie
    Replies: 1
    Last Post: 29th November 2007, 12:41

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.