Qt-interest Archive, May 2007
about signals and slots
Message 1 in thread
Hi, all
I am using qt4.
One question related to signals and slots:
I want to pass a parameter to user-defined slots(custom slots), but the
relevant qt pre-defined signals couldn't satisfy my needs. Then how to
define custom signals?
For example, passing an int i to a custom slot when clicked a
QPushbutton. None of QPushButton pre-defined signals contains a int
parameter, such as clicked(), pressed(), toggled(bool checked) ect.
{
int i;
connect(QPushButton, SIGNAL(someCustomSignal(int i)), this,
SLOT(someCustomSlot(int i)));
}
Thanks in advance.
Best regards
Feng-li
Message 2 in thread
u can declare slots and signals like this:
public slots:
returnType someCustomslot(valueType *,valueType * ,....);
signals:
void someCustomSignal(valueType*...);
2007/5/6, 张凤丽 <zhangfenglisdu@xxxxxxxxx>:
>
> Hi, all
> I am using qt4.
> One question related to signals and slots:
> I want to pass a parameter to user-defined slots(custom slots), but the
> relevant qt pre-defined signals couldn't satisfy my needs. Then how to
> define custom signals?
> For example, passing an int i to a custom slot when clicked a
> QPushbutton. None of QPushButton pre-defined signals contains a int
> parameter, such as clicked(), pressed(), toggled(bool checked) ect.
> {
> int i;
> connect(QPushButton, SIGNAL(someCustomSignal(int i)), this,
> SLOT(someCustomSlot(int i)));
> }
>
> Thanks in advance.
> Best regards
> Feng-li
>
Message 3 in thread
> Then how to define custom signals?
Recommended reading:
http://doc.trolltech.com/4.2/signalsandslots.html
--
[ signature omitted ]
Message 4 in thread
J-P Nurmi schrieb:
>> Then how to define custom signals?
>
> Recommended reading:
> http://doc.trolltech.com/4.2/signalsandslots.html
>
...and after reading the above you might be interested in that class:
http://doc.trolltech.com/4.2/qsignalmapper.html
Regards
Daniel
--
[ signature omitted ]
Message 5 in thread
On 06.05.07 16:50:45, ååä wrote:
> Hi, all
> I am using qt4.
> One question related to signals and slots:
> I want to pass a parameter to user-defined slots(custom slots), but the
> relevant qt pre-defined signals couldn't satisfy my needs. Then how to
> define custom signals?
> For example, passing an int i to a custom slot when clicked a
> QPushbutton. None of QPushButton pre-defined signals contains a int
> parameter, such as clicked(), pressed(), toggled(bool checked) ect.
> {
> int i;
> connect(QPushButton, SIGNAL(someCustomSignal(int i)), this,
> SLOT(someCustomSlot(int i)));
> }
Apart from what was already said, if you really needs a custom clicked()
signal you have to subclass QPushButton add the custom signal and a
private slot to your class. Then in the constructor connect the
QPushButton clicked() signal to your private slot and in the slot you
can emit your custom signal.
Andreas
--
[ signature omitted ]
Message 6 in thread
Hi,once again
It's my first time to hear about QSignalMapper class. After reading relevant
docs about it, I think maybe it does not work well with my situation.
Because the parameter which I want to pass to my custom slot does not
correspond with the object that sent the signal, still taking QPushButton's
clicked() pre-defined signal as example. The parameter is just a plain
variable, an int variable, ect.
Regards
fengli
correlativea QPushButton rele
2007/5/6, Andreas Pakulat <apaku@xxxxxx>:
>
> On 06.05.07 16:50:45, 张凤丽 wrote:
> > Hi, all
> > I am using qt4.
> > One question related to signals and slots:
> > I want to pass a parameter to user-defined slots(custom slots), but the
> > relevant qt pre-defined signals couldn't satisfy my needs. Then how to
> > define custom signals?
> > For example, passing an int i to a custom slot when clicked a
> > QPushbutton. None of QPushButton pre-defined signals contains a int
> > parameter, such as clicked(), pressed(), toggled(bool checked) ect.
> > {
> > int i;
> > connect(QPushButton, SIGNAL(someCustomSignal(int i)), this,
> > SLOT(someCustomSlot(int i)));
> > }
>
> Apart from what was already said, if you really needs a custom clicked()
> signal you have to subclass QPushButton add the custom signal and a
> private slot to your class. Then in the constructor connect the
> QPushButton clicked() signal to your private slot and in the slot you
> can emit your custom signal.
>
> Andreas
>
> --
> Cold hands, no gloves.
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
Message 7 in thread
>
> Hi,once again
> It's my first time to hear about QSignalMapper class. After reading
> relevant docs about it, I think maybe it does not work well with my
> situation. Because the parameter which I want to pass to my custom slot does
> not correspond with the object that sent the signal, still taking
> QPushButton's clicked() pre-defined signal as example. The parameter is just
> a plain variable, an int variable, ect.
> Regards
> fengli
>
>
> 2007/5/6, Andreas Pakulat <apaku@xxxxxx>:
> >
> > On 06.05.07 16:50:45, 张凤丽 wrote:
> > > Hi, all
> > > I am using qt4.
> > > One question related to signals and slots:
> > > I want to pass a parameter to user-defined slots(custom slots), but
> > the
> > > relevant qt pre-defined signals couldn't satisfy my needs. Then how to
> >
> > > define custom signals?
> > > For example, passing an int i to a custom slot when clicked a
> > > QPushbutton. None of QPushButton pre-defined signals contains a int
> > > parameter, such as clicked(), pressed(), toggled(bool checked) ect.
> > > {
> > > int i;
> > > connect(QPushButton, SIGNAL(someCustomSignal(int i)), this,
> > > SLOT(someCustomSlot(int i)));
> > > }
> >
> > Apart from what was already said, if you really needs a custom clicked()
> >
> > signal you have to subclass QPushButton add the custom signal and a
> > private slot to your class. Then in the constructor connect the
> > QPushButton clicked() signal to your private slot and in the slot you
> > can emit your custom signal.
> >
> > Andreas
> >
> > --
> > Cold hands, no gloves.
> >
> > --
> > To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> > "unsubscribe" in the subject or the body.
> > List archive and information: http://lists.trolltech.com/qt-interest/
> >
> >
>
Message 8 in thread
Hi,
Maybe I should do it like this(To be honest, I am not sure about it.):
//class declare
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow();
protected:
void closeEvent(QCloseEvent *event);
void paintEvent(QPaintEvent *event);
private slots:
void customslot1();
void customslot2(int i);
signals:
void customsignal(int i);
...
}
//class implement
MainWindow::MainWindow()
{
...
for (int i = 0 ; i < QStringList.size(); i++)
{
QPushButton *button = new QPushButton(this);
button->setText(QStringList[i]);
connect(button, SIGNAL(clicked()), this, SLOT(customslot1()));
connect(this, SIGNAL(customsignal(i)), this, SLOT(customslot2(i)));
}
...
}
Regards
Fengli
2007/5/6, 张凤丽 <zhangfenglisdu@xxxxxxxxx>:
>
> Hi,once again
> > It's my first time to hear about QSignalMapper class. After reading
> > relevant docs about it, I think maybe it does not work well with my
> > situation. Because the parameter which I want to pass to my custom slot does
> > not correspond with the object that sent the signal, still taking
> > QPushButton's clicked() pre-defined signal as example. The parameter is just
> > a plain variable, an int variable, ect.
> > Regards
> > fengli
> >
> >
> > 2007/5/6, Andreas Pakulat <apaku@xxxxxx>:
> > >
> > > On 06.05.07 16:50:45, 张凤丽 wrote:
> > > > Hi, all
> > > > I am using qt4.
> > > > One question related to signals and slots:
> > > > I want to pass a parameter to user-defined slots(custom slots), but
> > > the
> > > > relevant qt pre-defined signals couldn't satisfy my needs. Then how
> > > to
> > > > define custom signals?
> > > > For example, passing an int i to a custom slot when clicked a
> > > > QPushbutton. None of QPushButton pre-defined signals contains a int
> > > > parameter, such as clicked(), pressed(), toggled(bool checked) ect.
> > > > {
> > > > int i;
> > > > connect(QPushButton, SIGNAL(someCustomSignal(int i)), this,
> > > > SLOT(someCustomSlot(int i)));
> > > > }
> > >
> > > Apart from what was already said, if you really needs a custom
> > > clicked()
> > > signal you have to subclass QPushButton add the custom signal and a
> > > private slot to your class. Then in the constructor connect the
> > > QPushButton clicked() signal to your private slot and in the slot you
> > > can emit your custom signal.
> > >
> > > Andreas
> > >
> > > --
> > > Cold hands, no gloves.
> > >
> > > --
> > > To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> > > "unsubscribe" in the subject or the body.
> > > List archive and information: http://lists.trolltech.com/qt-interest/
> > >
> > >
> >
>
Message 9 in thread
Hi,
Last post I forgot to implement customslot1(), now add it here:
void MainWindow::customslot1()
{
emit customsignal(int i);
}
2007/5/6, 张凤丽 <zhangfenglisdu@xxxxxxxxx>:
>
> Hi,
> Maybe I should do it like this(To be honest, I am not sure about it.):
> //class declare
> class MainWindow : public QMainWindow
> {
> Q_OBJECT
> public:
> MainWindow();
> protected:
> void closeEvent(QCloseEvent *event);
> void paintEvent(QPaintEvent *event);
> private slots:
> void customslot1();
> void customslot2(int i);
> signals:
> void customsignal(int i);
> ...
> }
>
> //class implement
> MainWindow::MainWindow()
> {
> ...
> for (int i = 0 ; i < QStringList.size(); i++)
> {
> QPushButton *button = new QPushButton(this);
> button->setText(QStringList[i]);
> connect(button, SIGNAL(clicked()), this, SLOT(customslot1()));
> connect(this, SIGNAL(customsignal(i)), this, SLOT(customslot2(i)));
> }
> ...
> }
>
> Regards
> Fengli
>
>
> 2007/5/6, 张凤丽 <zhangfenglisdu@xxxxxxxxx>:
> >
> > Hi,once again
> > > It's my first time to hear about QSignalMapper class. After reading
> > > relevant docs about it, I think maybe it does not work well with my
> > > situation. Because the parameter which I want to pass to my custom slot does
> > > not correspond with the object that sent the signal, still taking
> > > QPushButton's clicked() pre-defined signal as example. The parameter is just
> > > a plain variable, an int variable, ect.
> > > Regards
> > > fengli
> > >
> > >
> > > 2007/5/6, Andreas Pakulat <apaku@xxxxxx>:
> > > >
> > > > On 06.05.07 16:50:45, 张凤丽 wrote:
> > > > > Hi, all
> > > > > I am using qt4.
> > > > > One question related to signals and slots:
> > > > > I want to pass a parameter to user-defined slots(custom slots),
> > > > but the
> > > > > relevant qt pre-defined signals couldn't satisfy my needs. Then
> > > > how to
> > > > > define custom signals?
> > > > > For example, passing an int i to a custom slot when clicked a
> > > > > QPushbutton. None of QPushButton pre-defined signals contains a
> > > > int
> > > > > parameter, such as clicked(), pressed(), toggled(bool checked)
> > > > ect.
> > > > > {
> > > > > int i;
> > > > > connect(QPushButton, SIGNAL(someCustomSignal(int i)), this,
> > > > > SLOT(someCustomSlot(int i)));
> > > > > }
> > > >
> > > > Apart from what was already said, if you really needs a custom
> > > > clicked()
> > > > signal you have to subclass QPushButton add the custom signal and a
> > > > private slot to your class. Then in the constructor connect the
> > > > QPushButton clicked() signal to your private slot and in the slot
> > > > you
> > > > can emit your custom signal.
> > > >
> > > > Andreas
> > > >
> > > > --
> > > > Cold hands, no gloves.
> > > >
> > > > --
> > > > To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> > > > "unsubscribe" in the subject or the body.
> > > > List archive and information:
> > > > http://lists.trolltech.com/qt-interest/
> > > >
> > > >
> > >
> >
>