1、声明:
protected slots:
virtual void Message( int flag );
2、定义:
void MyDialog::Message( int flag )
{
if( flag == 1 )
{
QMessageBox::information( this,
"Curve plot for ASCII data",
"<p>This tool provide you the ability to display multi-curves</p>",
"Ok",
0 );
}
else if( flag == 2 )
{
QMessageBox::warning( this,
"Curve plot for ASCII data",
"There is No file be selected !!!",
"Ok",
0 );
}
}
3、连接:
connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( Message( 1 ) ) );
4、编译成功,运行报错:
[chenxh@c12 drawline]$ QObject::connect: No such slot MyDialog::Message(1)
QObject::connect: (sender name: 'buttonHelp')
QObject::connect: (receiver name: 'MyDialog')
其中:
QPushButton* buttonHelp;
QPushButton* buttonOk;
QPushButton* buttonCancel;
—————————————————————————————————————————————
小豆子(8349695) 16:21:52
信号的参数个数不能少于槽的参数 个数
connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( Message( 1 ) ) );
无参数 一个参数
所以会出错!
碧空烈日(379069741) 16:29:49
两种方法,不知道行不行?
一就是小豆子所说的方法
二就是写一个类,继承MOUSE事件,然后发送一个自定义的signal
反语(522071254) 16:32:45
小碧说的有道理,或者是你用虚函数或不正确的继承关系,虽然奇趣说信号量和反应槽可以是普通函数,但这个问题也不一定就没问题。
————————————————————————————————————————————
由于本人懒惰,决定将槽做成两个,分别调用,如果大家有什么好的方法,不妨在此留下解决的办法!