Cannot setup Inherited class's method as slot for click signal
So basically I inherited from QPushButton and I want to handle the signal right inside the class. I also promoted the button I want to this new class.
So I did:
QObject::connect(ui->pickWatermarkButton, SIGNAL(clicked()),ui->pickWatermarkButton, SLOT(handleButton()));
The handleButton exists and is declared as a public slot. However, when I click the button, nothing happens.
I changed the slot to a location function, inside mainWindow, and surprise, it works! Apparently it only refuses to work when I try to use as a slot a method in the inherited class!
To solve this, just add the Q_OBJECT macro to your inherited class.
If you get "undefined reference to vtable" compilation errors, make sure you defined a destructor. If they still appear, right click on your project and select "run qmake", and then build your project again.
链接地址: http://www.djcxy.com/p/39298.html上一篇: 为什么我不能在第一次点击按钮时在Qt Widget上绘制点
下一篇: 无法将继承的类的方法设置为点击信号的插槽