Results 1 to 11 of 11

Thread: How can I know which button click.

  1. #1
    Join Date
    Oct 2009
    Posts
    30
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default How can I know which button click.

    sory for my bad english. I have two buttons. And two buttons are connecting to slot for click signal. But slots are equal.

    An Example;

    Qt Code:
    1. connect(bottun1,SIGNAL(clicked()),this,SLOT(MyClickEvent()));
    2. connect(button2,SIGNAL(clicked()),this,SLOT(MyClickEvent()));
    To copy to clipboard, switch view to plain text mode 

    How can I know which button click?
    Last edited by electronicboy; 3rd October 2009 at 14:10.

  2. #2
    Join Date
    Dec 2008
    Location
    TaganrogNativelandChehov,Russia
    Posts
    64
    Thanks
    1
    Thanked 8 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How can I know which button click.

    see
    QObject::sender()
    east or west home is best

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

    electronicboy (4th October 2009)

  4. #3
    Join Date
    Oct 2009
    Posts
    30
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How can I know which button click.

    @kwisp thanks. I looked sender but i didn t find properties. I want to ObjectName and I try

    sender()->ObjectName() but it's null.

    Edit: I solve this problem I write

    button1->setObjectName("button1");

    and running now.

    I have an array and I want to create buttons for each member of this array. can you help me?
    Last edited by electronicboy; 3rd October 2009 at 18:34.

  5. #4
    Join Date
    Dec 2008
    Location
    TaganrogNativelandChehov,Russia
    Posts
    64
    Thanks
    1
    Thanked 8 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How can I know which button click.

    Quote Originally Posted by electronicboy View Post
    ...
    I have an array and I want to create buttons for each member of this array. can you help me?
    I do not understand you.
    Can you show me your code.?
    east or west home is best

  6. #5
    Join Date
    Jan 2006
    Location
    Knivsta, Sweden
    Posts
    153
    Thanks
    30
    Thanked 13 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: How can I know which button click.

    With QSignalMapper you can have your slot called with an (e.g. integer) argument that is different for each button.

  7. #6
    Join Date
    Oct 2009
    Posts
    30
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How can I know which button click.

    Hi,

    I have programme in C#.Net. But I want to write application for embedded operation system and i use QT.

    in C#.net code
    Qt Code:
    1. //Button Arraylist
    2. string[] buttonsarray = new string[2] { "firstbutton", "secondbutton"};
    3.  
    4.  
    5. Dictionary<string, Button> buttonlist = new Dictionary<string, Button>();
    6. private void createButton()
    7. {
    8. //each index of this array
    9. foreach (string name in buttonsarray)
    10. {
    11. this.buttonlist[name] = new Button();
    12. this.buttonlist[name].Text = name;
    13. this.buttonlist[name].Location = new System.Drawing.Point(16*(countx+1) + padding * countx, 10);
    14. this.buttonlist[name].Size = new System.Drawing.Size(95, 145);
    15. // Show form
    16. this.Controls.Add(buttonlist[name]);
    17. countx += 1;
    18. }
    19. }
    To copy to clipboard, switch view to plain text mode 

  8. #7
    Join Date
    Jan 2006
    Location
    Knivsta, Sweden
    Posts
    153
    Thanks
    30
    Thanked 13 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: How can I know which button click.

    ...and your question is ... ?

  9. #8
    Join Date
    Oct 2009
    Posts
    30
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How can I know which button click.

    How can I create buttons from arraylist?

  10. #9
    Join Date
    Sep 2009
    Posts
    36
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How can I know which button click.

    use a signal with an int parameter:
    Qt Code:
    1. class YourButton {
    2. public:
    3. // stuff here
    4. private:
    5. int id;
    6. signals:
    7. void buttonPressed(int);
    8. };
    To copy to clipboard, switch view to plain text mode 

    and now just give any button an ID at creation. and send that within the signal so you can distinguish between buttons (and of course the slot should have an int argument aswell)


    so whenever a button is pressed (detect that via the QPushButton signals ( bind a slot with that and then emit your own signal)).

    Qt Code:
    1. emit buttonPressed(id);
    To copy to clipboard, switch view to plain text mode 



    What kind of data does your array / list hold?

  11. #10
    Join Date
    Oct 2009
    Posts
    30
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How can I know which button click.

    Quote Originally Posted by soxs060389 View Post
    use a signal with an int parameter:
    Qt Code:
    1. class YourButton {
    2. public:
    3. // stuff here
    4. private:
    5. int id;
    6. signals:
    7. void buttonPressed(int);
    8. };
    To copy to clipboard, switch view to plain text mode 

    and now just give any button an ID at creation. and send that within the signal so you can distinguish between buttons (and of course the slot should have an int argument aswell)


    so whenever a button is pressed (detect that via the QPushButton signals ( bind a slot with that and then emit your own signal)).

    Qt Code:
    1. emit buttonPressed(id);
    To copy to clipboard, switch view to plain text mode 



    What kind of data does your array / list hold?
    List hold is button name.

  12. #11
    Join Date
    Oct 2009
    Posts
    30
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How can I know which button click.

    Hi all.

    I could not tell my trouble. I have an arraylist. For example;

    Qt Code:
    1. QList<QPushButton*> buttonlist;
    2. buttonlist << button1<<button2<<button3;
    To copy to clipboard, switch view to plain text mode 

    This arraylist is changeable as you know. And Qt want to definition for QPushButton(button1,button2,button3) . How can I define this QPushBotton. I hope I can tell my problem.

Similar Threads

  1. button click in webview
    By mind_freak in forum Qt Programming
    Replies: 1
    Last Post: 29th September 2009, 13:48
  2. How to open any file on button click???
    By r3aktor in forum Newbie
    Replies: 5
    Last Post: 8th July 2009, 08:54
  3. QMdiSubWindow not delet when click the X button.
    By SamSong in forum Qt Programming
    Replies: 1
    Last Post: 20th May 2009, 08:21
  4. QPaintEvent on button click?
    By vishal.chauhan in forum Qt Programming
    Replies: 1
    Last Post: 5th June 2007, 08:44
  5. Push button double click
    By curtisw in forum Qt Programming
    Replies: 3
    Last Post: 15th February 2006, 16:40

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.