Qt:postEvent 与 customEvent() 函数 进行异步通信; 以及参数的传递 // 防止界面卡死;;


 

 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();
        }
    }
    

 

 

// 可以进行类型的转化;;


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM