class ColorChangeEvent : public QCustomEvent
{
public:
ColorChangeEvent( QColor color )
: QCustomEvent( ), c( color ) {}
QColor color() const { return c; }
private:
QColor c;
}; // To send an event of this custom event type: ColorChangeEvent* ce = new ColorChangeEvent( blue );
QApplication::postEvent( receiver, ce ); // Qt will delete it when done // To receive an event of this custom event type: void MyWidget::customEvent( QCustomEvent * e )
{
if ( e->type() == ) { // It must be a ColorChangeEvent
ColorChangeEvent* ce = (ColorChangeEvent*)e;
newColor = ce->color();
}
}
// 可以进行类型的转化;;