Qt-interest Archive, May 2007
QAction signals
Message 1 in thread
Hi, all
First see a small segment codes:
QAction *positionTypeAction;
positionTypeAction= new QAction(this);
positionTypeAction->setCheckable(true);
connect(positionTypeAction, SIGNAL(toggled(isChecked())), this,
SLOT(showPositionType(bool checked)));
When I compile it , nothing errors occurs. But I receive errors when trying
to run it. Error is as follows:
Object::connect: No such signal QAction::toggled(bool checked)
Object::connect: (sender name: 'positionTypeAction')
Object::connect: (receiver name: 'MainWindow')
How to fix it should I?
Thanks for any information
Best wishes
Fengli
Message 2 in thread
张凤丽 wrote:
> QAction *positionTypeAction;
> positionTypeAction= new QAction(this);
> positionTypeAction->setCheckable(true);
> connect(positionTypeAction, SIGNAL(toggled(isChecked())), this,
> SLOT(showPositionType(bool checked)));
>
Change "toggled(isChecked())" to "toggled(bool)".
--Dave
--
[ signature omitted ]
Message 3 in thread
Hi,
>> QAction *positionTypeAction;
>> positionTypeAction= new QAction(this);
>> positionTypeAction->setCheckable(true);
>> connect(positionTypeAction, SIGNAL(toggled(isChecked())), this,
>> SLOT(showPositionType(bool checked)));
>>
>
> Change "toggled(isChecked())" to "toggled(bool)".
Also change "showPositionType(bool checked)" to "showPositionType(bool)".
--
[ signature omitted ]
Message 4 in thread
Hi, again
Then how to pass the bool parameter from the signal to the slot, or get the
return value of QAction->isChecked() in the slot, as follows?
void MainWindow::showPositionType(bool)
{
bool checked;
checked = positionTypeAction->isChecked();
if (checked)
{
.....
}
else
{
.....
}
}
2007/5/22, 张凤丽 <zhangfenglisdu@xxxxxxxxx>:
>
> Hi, all
> First see a small segment codes:
>
> QAction *positionTypeAction;
> positionTypeAction= new QAction(this);
> positionTypeAction->setCheckable(true);
> connect(positionTypeAction, SIGNAL(toggled(isChecked())), this,
> SLOT(showPositionType(bool checked)));
>
> When I compile it , nothing errors occurs. But I receive errors when
> trying to run it. Error is as follows:
> Object::connect: No such signal QAction::toggled(bool checked)
> Object::connect: (sender name: 'positionTypeAction')
> Object::connect: (receiver name: 'MainWindow')
>
> How to fix it should I?
> Thanks for any information
> Best wishes
> Fengli
>
Message 5 in thread
Look into sender(), or QSignalMapper depending on how many actions you have tied to the slot
________________________________
From: 张凤丽 [mailto:zhangfenglisdu@xxxxxxxxx]
Sent: Tuesday, May 22, 2007 6:52 PM
To: qt-interest
Subject: Re: QAction signals
Hi, again
Then how to pass the bool parameter from the signal to the slot, or get the return value of QAction->isChecked() in the slot, as follows?
void MainWindow::showPositionType(bool)
{
bool checked;
checked = positionTypeAction->isChecked();
if (checked)
{
.....
}
else
{
.....
}
}
2007/5/22, 张凤丽 < zhangfenglisdu@xxxxxxxxx>:
Hi, all
First see a small segment codes:
QAction *positionTypeAction;
positionTypeAction= new QAction(this);
positionTypeAction->setCheckable(true);
connect(positionTypeAction, SIGNAL(toggled(isChecked())), this, SLOT(showPositionType(bool checked)));
When I compile it , nothing errors occurs. But I receive errors when trying to run it. Error is as follows:
Object::connect: No such signal QAction::toggled(bool checked)
Object::connect: (sender name: 'positionTypeAction')
Object::connect: (receiver name: 'MainWindow')
How to fix it should I?
Thanks for any information
Best wishes
Fengli
Message 6 in thread
张凤丽 wrote:
> void MainWindow::showPositionType(bool)
> {
> bool checked;
> checked = positionTypeAction->isChecked();
> if (checked)
> {
> .....
> }
> else
> {
> .....
> }
> }
>
Do this instead:
void MainWindow::showPositionType(bool checked)
{
if (checked)
{
.....
}
else
{
.....
}
}
--
[ signature omitted ]