Results 1 to 3 of 3

Thread: signal mapping on pushbutton signal clicked

  1. #1
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default signal mapping on pushbutton signal clicked

    hi friends,
    i try to set the QPushButton() signal clicked() to connect
    a slot changeIndex(int)

    so i try signal Mapper so i do
    mapping .h
    Qt Code:
    1. #include <QSignalMapper>
    2.  
    3. signals:
    4. void clicked(int value);
    5.  
    6. public Q_SLOTS:
    7. void changeIndex(int index);
    8.  
    9. private:
    10. QSignalMapper *signalMapper;
    11. int mapValue[10];
    To copy to clipboard, switch view to plain text mode 

    in mapping.cpp
    Qt Code:
    1. /* signal Mapper*/
    2. mapValue[i] = 2;
    3. connect(cicsButton, SIGNAL(clicked()), signalMapper, SLOT(map()));
    4. signalMapper->setMapping(cicsButton, mapValue[1]);
    5.  
    6. connect(signalMapper, SIGNAL(mapped(int)), this, SIGNAL(clicked(int)));
    7. connect(this, SIGNAL(clicked(int)), this, SLOT(changeIndex(int)));
    To copy to clipboard, switch view to plain text mode 

    it compiled perfectly but when i run core dumped
    when i try execute it gives Segmentation fault ....

    i dont know where i done the mistake ...it crashes here ..
    Qt Code:
    1. connect(cicsButton, SIGNAL(clicked()), signalMapper, SLOT(map()));
    To copy to clipboard, switch view to plain text mode 

    please help .... why in run time it give seg. fault ....

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: signal mapping on pushbutton signal clicked

    [offtop]
    you can optimazi this code
    Qt Code:
    1. connect(signalMapper, SIGNAL(mapped(int)), this, SIGNAL(clicked(int)));
    2. connect(this, SIGNAL(clicked(int)), this, SLOT(changeIndex(int)));
    To copy to clipboard, switch view to plain text mode 
    like this
    Qt Code:
    1. connect(signalMapper, SIGNAL(mapped(int)), this, SIGNAL(changeIndex(int)));
    To copy to clipboard, switch view to plain text mode 
    [/offtop]

    could you post compilable code which reproduces a crash?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

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

    wagmare (17th March 2009)

  4. #3
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: signal mapping on pushbutton signal clicked

    Quote Originally Posted by spirit View Post
    [offtop]
    you can optimazi this code
    Qt Code:
    1. connect(signalMapper, SIGNAL(mapped(int)), this, SIGNAL(clicked(int)));
    2. connect(this, SIGNAL(clicked(int)), this, SLOT(changeIndex(int)));
    To copy to clipboard, switch view to plain text mode 
    like this
    Qt Code:
    1. connect(signalMapper, SIGNAL(mapped(int)), this, SIGNAL(changeIndex(int)));
    To copy to clipboard, switch view to plain text mode 
    [/offtop]

    could you post compilable code which reproduces a crash?
    thanks for reply ...
    sorry to the forum members ... i forget to initialize signalMapper
    signalMapper = new QSignalMapper();
    now its working ... sorry for this post ....

Similar Threads

  1. QTreeWidget clicked signal
    By ^NyAw^ in forum Qt Programming
    Replies: 41
    Last Post: 30th January 2010, 11:42
  2. pthread instead QThread
    By brevleq in forum Qt Programming
    Replies: 8
    Last Post: 23rd December 2008, 07:16
  3. Connection of custon signals/slots
    By brevleq in forum Qt Programming
    Replies: 2
    Last Post: 23rd December 2008, 07:04
  4. disable clicked() signal
    By mattia in forum Newbie
    Replies: 2
    Last Post: 27th February 2008, 10:27
  5. Replies: 10
    Last Post: 27th January 2006, 18:12

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.