其实我可以这样做: 在mainfen.h中:
private:
QPushButton *m_edit; //declare the button
在mainfen.cpp中:
mainFen::mainFen()
{
[...]
m_edit = new QPushButton; //create a new button
m_edit->setCheckable(true); //set a property of it
[...]
}
void mainFen::onSomethingClicked() // is a slot
{
[...]
m_edit->setChecked(true); //we want to set a property of the button
[...]
}
但我不认为这是正确的方法,我认为我必须这样做: mainfen.h没有* m_edit定义,mainfen.cpp是:
mainFen::mainFen()
{
[...]
QPushButton *edit = new QPushButton; //create a new button
edit->setCheckable(true); //set a property of it
[...]
}
void mainFen::onSomethingClicked() // is a slot
{
[...]
edit->setChecked(true); //we want to set a property of the button
[...]
}
但这不起作用,因为编辑不是onSomethingClicked()插槽的一部分,我怎样才能使它工作?提前谢谢。