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;
Code:
connect(bottun1,SIGNAL(clicked()),this,SLOT(MyClickEvent()));
connect(button2,SIGNAL(clicked()),this,SLOT(MyClickEvent()));
How can I know which button click?
Re: How can I know which button click.
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?
Re: How can I know which button click.
Quote:
Originally Posted by
electronicboy
...
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.?
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.
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
Code:
//Button Arraylist
string[] buttonsarray = new string[2] { "firstbutton", "secondbutton"};
Dictionary<string, Button> buttonlist = new Dictionary<string, Button>();
private void createButton()
{
//each index of this array
foreach (string name in buttonsarray)
{
this.buttonlist[name] = new Button();
this.buttonlist[name].Text = name;
this.buttonlist[name].Location = new System.Drawing.Point(16*(countx+1) + padding * countx, 10);
this.buttonlist[name].Size = new System.Drawing.Size(95, 145);
// Show form
this.Controls.Add(buttonlist[name]);
countx += 1;
}
}
Re: How can I know which button click.
...and your question is ... ?
Re: How can I know which button click.
How can I create buttons from arraylist?
Re: How can I know which button click.
use a signal with an int parameter:
Code:
class YourButton {
public:
// stuff here
private:
int id;
signals:
void buttonPressed(int);
};
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)).
Code:
emit buttonPressed(id);
What kind of data does your array / list hold?
Re: How can I know which button click.
Quote:
Originally Posted by
soxs060389
use a signal with an int parameter:
Code:
class YourButton {
public:
// stuff here
private:
int id;
signals:
void buttonPressed(int);
};
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)).
Code:
emit buttonPressed(id);
What kind of data does your array / list hold?
List hold is button name.
Re: How can I know which button click.
Hi all.
I could not tell my trouble. I have an arraylist. For example;
Code:
QList<QPushButton*> buttonlist;
buttonlist << button1<<button2<<button3;
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.