文件名称:自定义事件-实例-qt开发文档
文件大小:541KB
文件格式:PPT
更新时间:2024-05-16 03:17:14
qt-Linux
自定义事件-实例 class ColorChangeEvent : public QCustomEvent { public: ColorChangeEvent( QColor color ) : QCustomEvent( 65432 ), 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() == 65432 ) { // It must be a ColorChangeEvent ColorChangeEvent* ce = (ColorChangeEvent*)e; newColor = ce->color(); } }