Java. net mfc qt Event Processing Mechanism

Source: Internet
Author: User

Java Event Processing Mechanism
1. Develop Custom Event classes.
Public class propertyevent extends eventobject {
Public propertyevent (){}
}
2. Define the listener interface.
Public interface propertylistener extends eventlistener {
Public void propertychanged (propertyevent );
}
3. Define the interface of the event initiator.
Public void add listener (listener );
Public void remove listener (listener );
Protected void process event (event );
4. Events are triggered.
5. Implement the listener interface.

MFC practice
Afx_msg void onappabout ();
Declare_message_map ()
Begin_message_map (ctapp, cwinapp)
On_command (id_app_about, onappabout)
End_message_map ()

Use Events in c #
1. Create a delegate Public Delegate void delegateme (Object PARAM );
2. Associate the created delegate with a specific event public event delegateme eventme;
3. Write the event handler public void Policy (); policyeveryone ();
4. Use the compiled event handler to generate a delegate instance DelegateEvent eventSource = new DelegateEvent ();
5. Add the delegated instance to the event list that generates the event object. This process is also called subscription event eventSource. ~yeveryone + = new event_test.DelegateEvent.MyDelegate (objA. DispMethodA );
6. Use this event eventSource. Y ();
QT event processing


When the internal state of an object changes, the signal is sent. In some ways, it may be interesting for the object proxy or owner. Only the class that defines a signal and its subclass can transmit this signal.
Class Foo: public
QObject
{

Q_OBJECT
Public:
Foo ();
Int value () const {return val ;}
Public slots:
Void setValue (int); // slot
Signals:
Void valueChanged (int); // Signal
Private:
Int val;
};
When a signal connected to the slot is sent, the slot is called. Slots are common C ++ functions and can be called like them. Their only feature is that they can be connected by signals. The Slot Parameter cannot contain the default value, and is the same as the signal. It is unwise to use a specific type for slot parameters.
Foo a, B;
Connect (& a, SIGNAL (valueChanged (int), & B, SLOT (setValue (int); // connect
B. setValue (11 );
A. setValue (79 );
B. value ();
Message Processing Process of QT
Bool MyClass: event (
QEvent * E ){
If (e-> type () = QEvent: KeyPress ){
QKeyEvent * Ke = (QKeyEvent *) e;
If (ke-> key () = Key_Tab ){
// Specific tab Processing
K-> accept ();
Return TRUE;
}
} Else if (e-> type ()> = QEvent: User ){
QCustomEvent * C = (QCustomEvent *) e;
// Here is the Custom Event Processing
Return TRUE;
}
QWidget: event (E );
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.