A QT event transmission method and device, computer equipment and storage medium

By using event queues and timer IDs for event passing in QT, the problems of cumbersome event passing and poor management in existing technologies are solved, enabling fast and simple event processing and delay time specification.

CN116414584BActive Publication Date: 2026-07-28BEI DOU ZHI LIAN KE JI YOU XIAN GONG SI
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310402174.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-04-13
Publication Date
2026-07-28
Estimated Expiration
2043-04-13

AI Technical Summary

Technical Problem

Existing technologies that use QT's native API to implement event propagation are cumbersome, time-consuming to run, and have poor event management.

Method used

By creating an event queue, managing event delay processing using timer IDs, quickly acquiring events using signals and slot functions, and specifying the event delay time using timer IDs.

Benefits of technology

It enables unified management of events, simplifies the event handling process, improves running speed, allows specification of event delay time, and optimizes QT event propagation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116414584B_ABST
    Figure CN116414584B_ABST
Patent Text Reader

Abstract

The application discloses a QT event transmission method and device, computer equipment and a storage medium, the method comprises the following steps: adding a to-be-processed event to an event queue by taking a second object as a parameter of an event sending function of a first object; acquiring an event sending signal, and acquiring a target to-be-processed event from the event queue according to the event sending signal; starting a timer according to a delay time length in the target to-be-processed event, and saving a timer ID number of the timer to a to-be-processed event corresponding to the target to-be-processed event in the event queue, so as to update the to-be-processed event in the event queue which saves the timer ID number to a delay processing event; executing a timer event function, acquiring the delay processing event from the event queue according to the timer ID number; and if it is determined that the delay processing event is successfully acquired, processing the delay processing event by using an event processing function. The application can uniformly manage events, specify the time required for event execution to be delayed, and has high running speed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of event handling technology, and in particular to a QT event transmission method, apparatus, computer device, and storage medium. Background Technology

[0002] Currently, Qt is widely used as a cross-platform software development framework. Event passing is a crucial aspect that Qt developers must be familiar with. During development, it is frequently necessary to pass events from one object to another, and sometimes it is also necessary to defer event handling for specific purposes.

[0003] The following are some existing methods for using QT event handling:

[0004] (1) Send a blocking event:

[0005] a. Define the class A that will handle the event, which inherits from class QObject.

[0006] b. Define the custom event class E to be transmitted, which inherits from the QEvent class.

[0007] c. Override the event method of class A, and filter and process the events to be received in this method.

[0008] d. Create an object a_obj of class A.

[0009] e. Create a custom event class E object e_obj to be passed.

[0010] f. Call the QApplication::sendEvent() function, using e_obj and a_obj as parameters, to pass the event e_obj to a_obj.

[0011] (2) Send non-blocking events:

[0012] a. Define the class A that will handle the event, which inherits from class QObject.

[0013] b. Define the custom event class E to be transmitted, which inherits from the QEvent class.

[0014] c. Override the event method of class A, and filter and process the events to be received in this method.

[0015] d. Create an object a_obj of class A.

[0016] e. Create a custom event class E object e_obj to be passed.

[0017] f. Call the QApplication::postEvent() function, using e_obj and a_obj as parameters, to pass the event e_obj to a_obj.

[0018] (3) Delayed execution events:

[0019] a. Define the delay time td.

[0020] b. Calculate the execution time, that is, obtain the sum t of the current time tc and the delay time td.

[0021] c. Use a while loop, with the condition that the current time tc is less than the time t of the event.

[0022] d. Execute the QCoreApplication::processEvents() function within the loop body.

[0023] However, the current technology of using QT's native API (Application Programming Interface) to implement event passing is cumbersome, time-consuming during program execution, and lacks event management. Therefore, it is very necessary to optimize QT's event passing. Summary of the Invention

[0024] This invention provides a QT event passing method, apparatus, computer device, and storage medium, aiming to solve the problems of cumbersome event passing using QT's native API, time-consuming program execution, and lack of event management in the prior art.

[0025] In a first aspect, embodiments of the present invention provide a QT event passing method, comprising:

[0026] Create an object of the event class to be processed, and obtain the first object;

[0027] Create an object of the event to be processed, and obtain a second object;

[0028] Using the second object as a parameter to call the event sending function of the first object, the event to be processed is added to the event queue; wherein, the event queue includes multiple other events to be processed;

[0029] Obtain an event sending signal, and retrieve the corresponding pending event from the event queue based on the event sending signal as the target pending event;

[0030] A timer is started based on the delay duration in the target pending event, and the timer ID number of the timer is saved to the pending event corresponding to the target pending event in the event queue, so as to update the pending event in the event queue that has the timer ID number saved to a delayed processing event;

[0031] Execute the timer event function to retrieve the delayed processing event from the event queue based on the timer ID number;

[0032] If the delayed processing event is successfully obtained, the delayed processing event is processed using the overridden event handling function.

[0033] Secondly, embodiments of the present invention provide a QT event transmission device, comprising:

[0034] The first creation unit is used to create an object of the event class to be processed, thus obtaining the first object;

[0035] The second creation unit is used to create an object of the event to be processed, thus obtaining a second object;

[0036] An event adding unit is used to add the event to be processed to an event queue by using the second object as a parameter to call the event sending function of the first object; wherein the event queue includes multiple other events to be processed;

[0037] An event acquisition unit is used to acquire an event sending signal and, based on the event sending signal, retrieve the corresponding event to be processed from the event queue as the target event to be processed.

[0038] The timed start unit is used to start a timer according to the delay duration in the target pending event, and save the timer ID number of the timer to the pending event corresponding to the target pending event in the event queue, so as to update the pending event with the timer ID number stored in the event queue to a delayed processing event;

[0039] The delay processing unit is used to execute a timer event function to retrieve the delay processing event from the event queue according to the timer ID number;

[0040] An event handling unit is used to process the delayed processing event using a rewritten event handling function if it is determined that the delayed processing event has been successfully obtained.

[0041] Thirdly, embodiments of the present invention provide a computer device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the QT event transmission method described in the first aspect above.

[0042] Fourthly, embodiments of the present invention also provide a computer-readable storage medium storing a computer program that, when executed by a processor, causes the processor to perform the QT event passing method described in the first aspect.

[0043] This invention provides a QT event passing method, apparatus, computer device, and storage medium. The method includes: creating an object of a class of events to be processed, obtaining a first object; creating an object of events to be processed, obtaining a second object; adding the events to be processed to an event queue using the second object as a parameter for calling the event sending function of the first object; wherein the event queue includes multiple other events to be processed; acquiring an event sending signal, and retrieving the corresponding event to be processed from the event queue as a target event to be processed based on the event sending signal; starting a timer according to the delay duration in the target event to be processed, and saving the timer ID number of the timer to the event queue corresponding to the target event to be processed, thereby updating the events to be processed in the event queue that have the timer ID number saved as delayed processing events; executing the timer event function, and retrieving the delayed processing event from the event queue according to the timer ID number; if it is determined that the delayed processing event has been successfully retrieved, processing the delayed processing event using the event handling function. This invention can manage events uniformly, specify the delay time required for event execution, and has a fast running speed. Attached Figure Description

[0044] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the following description of the embodiments will be briefly introduced. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0045] Figure 1 This is a flowchart illustrating a QT event transmission method provided in an embodiment of the present invention;

[0046] Figure 2 This is a schematic block diagram of a QT event transmission device provided in an embodiment of the present invention;

[0047] Figure 3 A schematic block diagram of a computer device provided for an embodiment of the present invention. Detailed Implementation

[0048] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0049] It should be understood that, when used in this specification and the appended claims, the terms "comprising" and "including" indicate the presence of the described features, integrals, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or collections thereof.

[0050] It should also be understood that the terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to limit the invention. As used in this specification and the appended claims, the singular forms “a,” “an,” and “the” are intended to include the plural forms unless the context clearly indicates otherwise.

[0051] It should also be further understood that the term "and / or" as used in this specification and the appended claims refers to any combination of one or more of the associated listed items and all possible combinations, and includes such combinations.

[0052] Please see Figure 1 , Figure 1 This is a flowchart illustrating the QT event passing method provided in an embodiment of the present invention. The QT event passing method provided in this embodiment is applied to a terminal, and is executed by application software installed on the terminal.

[0053] like Figure 1 As shown, the QT event transmission method provided in this embodiment of the invention includes steps S11 to S17.

[0054] S11. Create an object of the event class to be processed, and obtain the first object.

[0055] In this embodiment, before passing the event to be processed from one object to another, an object of the event class to be processed is created, resulting in the first object a_obj.

[0056] In one embodiment, prior to step S11, the QT event passing method further includes:

[0057] Create the event class to be processed that inherits from the event delegate class, and override the event handling function in the event class to be processed.

[0058] In this embodiment, before creating an object of the event class to be processed (i.e., the first object a_obj), it is necessary to create an event class that inherits from the event delegate class. The event delegate class is the EventHandler class, and the event class to be processed inherits from the EventHandler class, using EventHandler as its parent class. Then, the event handling function is overridden in the event class to be processed, specifically the handleEvent function. The handleEvent function is a callback function; by overriding the handleEvent function, the event handling action is redefined so that the received event (Event) can be processed within the handleEvent function.

[0059] S12. Create an object for the event to be processed, and obtain the second object.

[0060] In this embodiment, an object of the event to be processed (Event) is created, and a second object e_obj is obtained, so that the second object e_obj is used as a parameter of the event sending function.

[0061] S13. Using the second object as a parameter to call the event sending function of the first object, the event to be processed is added to the event queue; wherein, the event queue includes multiple other events to be processed.

[0062] In this embodiment, the event sending function of the first object a_obj, namely the sendEvent function, is called, using the second object e_obj as a parameter, thereby passing the event to be processed from e_obj to a_obj. Specifically, the sendEvent function of the first object a_obj is called, passing the event to be processed to the EventHandler class, and then the event to be processed is added to the event queue EventQueue. The EventQueue includes multiple other events to be processed. By adding events to the EventQueue, events are processed uniformly, simplifying usage and reducing the learning curve. Furthermore, using the EventQueue to manage events optimizes the problem of poor event management, and the process of sending events is simpler, reducing execution time.

[0063] S14. Obtain the event sending signal, and obtain the corresponding pending event from the event queue according to the event sending signal as the target pending event.

[0064] In this embodiment, after adding the event to be processed to the event queue EventQueue, an event sending signal signalSendEvent is sent. The event sending signal signalSendEvent is then obtained, and the corresponding event to be processed is retrieved from the event queue according to the event sending signal signalSendEvent. The retrieved event to be processed is then used as the target event to be processed.

[0065] In one embodiment, step S14 includes:

[0066] Obtain the target slot function and target event ID number corresponding to the event sending signal;

[0067] The target slot function retrieves the corresponding pending event from the event queue based on the target event ID, and uses the retrieved pending event as the target pending event.

[0068] In this embodiment, when a signal is emitted, the slot associated with that signal is executed; the slot is a function that responds to the signal. After adding the event to be processed (Event) to the event queue (EventQueue), an event sending signal (signalSendEvent) is emitted. This signal contains the target event ID (i.e., the parameter Event ID), which is used to retrieve the corresponding event to be processed from the event queue (EventQueue). The signal sends the target event ID to the corresponding target slot function (slotSendEvent). The target slot function (slotSendEvent) then receives the target event ID and uses it as a parameter to execute the target slot function. Based on the target event ID, the corresponding event to be processed is retrieved from the event queue (EventQueue), and this retrieved event is used as the target event to be processed. This combination of signals and slot functions allows for the rapid retrieval of the corresponding event to be processed from the event queue (EventQueue).

[0069] S15. Start a timer according to the delay duration in the target pending event, and save the timer ID number of the timer to the pending event corresponding to the target pending event in the event queue, so as to update the pending event with the timer ID number in the event queue to a delayed processing event.

[0070] In this embodiment, passing an event from one object to another sometimes requires delaying the processing of a specified event. Existing technologies using QT's API to send delayed events require implementing this through a loop. However, the QT event passing method provided in this embodiment starts a timer based on the delay duration in the target pending event, allowing for more precise delays by directly specifying the required delay time. Simultaneously, the timer ID is saved to the pending event corresponding to the target pending event in the EventQueue. This updates the pending event in the EventQueue with the timer ID as a delayed processing event, ensuring that when the timer reaches the delay duration of the target pending event, the corresponding delayed processing event can be retrieved from the EventQueue based on the timer ID. This allows QT event passing to be used as a timer, optimizing the issues of QT timers not having parameters and parameter management.

[0071] In one embodiment, step S15 includes:

[0072] Using the delay duration in the target event to be processed as a parameter for calling the first preset function, the timer is started and the timer ID number of the timer is returned; wherein, the first preset function is the Qobject::startTimer function;

[0073] The timer ID number is saved to the pending event corresponding to the target pending event in the event queue, so as to update the pending event with the timer ID number in the event queue to a delayed processing event.

[0074] In this embodiment, a timer is started by calling the `Qobject::startTimer` function. The function parameter is in milliseconds, representing the set duration, and returns a unique timer identifier. Specifically, using the delay duration in the target event as the parameter for calling `Qobject::startTimer` (e.g., if the delay duration in the target event is 15 seconds, then 15000 is used as the parameter), a timer with the set delay duration is started, and its timer ID is returned. Simultaneously, the timer ID is saved to the corresponding event in the `EventQueue`. This allows direct specification of the delay time for event execution, enabling the use of QT event propagation as a timer, thus optimizing the issues of QT timers not having parameters and parameter management.

[0075] S16. Execute the timer event function to retrieve the delayed processing event from the event queue according to the timer ID number.

[0076] In this embodiment, a timer event function is executed, which is the `timerEvent` function. When the timer reaches the delay duration of the target event to be processed, the `timerEvent` function will be entered to perform the necessary operations, retrieving the delayed processing event from the event queue `EventQueue` according to the timer ID number.

[0077] In one embodiment, after step S16, the method further includes:

[0078] If it is determined that the delayed processing event has not been deleted from the event queue, then the delayed processing event is deleted from the event queue.

[0079] In this embodiment, if a delayed event can be retrieved from the EventQueue based on the timer ID, it means that the event has not been deleted from the EventQueue within the specified delay time required for its execution. Therefore, after retrieving the delayed event from the EventQueue based on the timer ID, the delayed event is deleted from the EventQueue. Deleting the delayed event from the EventQueue saves storage space and facilitates the addition of new events.

[0080] In one embodiment, after step S16, the method further includes:

[0081] If it is determined that the delayed processing event was not successfully obtained, the process ends.

[0082] In this embodiment, if the delayed processing event cannot be successfully retrieved from the event queue EventQueue based on the timer ID, it means that the delayed processing event has been deleted from the event queue EventQueue within the delay time. Since the delayed processing event does not need to be processed, the termination step is executed to end the process.

[0083] S17. If it is determined that the delayed processing event has been successfully obtained, the delayed processing event is processed using the overridden event handling function.

[0084] In this embodiment, if a delayed processing event can be obtained from the event queue EventQueue based on the timer ID number, and it is determined that the delayed processing event has been successfully obtained, then the overridden event handling function is used to process the delayed processing event, that is, the handleEvent function is called to process the delayed processing event.

[0085] In one embodiment, after step S17, the method further includes:

[0086] Delete the delayed processing event from local storage.

[0087] In this embodiment, after calling the `handleEvent` function to process the delayed event, the delayed event is deleted from local storage to reduce local storage usage and improve system speed. Additionally, a deletion completion message can be generated and displayed after deleting the delayed event from local storage.

[0088] This invention provides a QT event passing method that unifies event processing, simplifies usage, and reduces learning costs. Furthermore, it utilizes an EventQueue to manage events, optimizing the problem of poor event management and simplifying the event sending process, thus reducing execution time. This invention optimizes QT event passing, featuring the ability to specify the delay time for event execution, improved event management, faster execution speed, cross-thread event passing, and the ability to be used as a timer.

[0089] This invention also provides a QT event passing device, which is used to execute any embodiment of the aforementioned QT event passing method. Specifically, please refer to... Figure 2 , Figure 2 This is a schematic block diagram of a QT event transmission device provided in an embodiment of the present invention. The QT event transmission device provided in an embodiment of the present invention includes a first creation unit 11, a second creation unit 12, an event adding unit 13, an event acquisition unit 14, a timed start unit 15, a delay processing unit 16, and an event processing unit 17.

[0090] The first creation unit 11 is used to create an object of the event class to be processed, and obtain the first object.

[0091] In this embodiment, before passing the event to be processed from one object to another, an object of the event class to be processed is created, resulting in the first object a_obj.

[0092] In one embodiment, the QT event transmission device further includes:

[0093] A class creation unit is used to create the event class to be processed that inherits from the event delegate class, and to override the event handling function in the event class to be processed.

[0094] In this embodiment, before creating an object of the event class to be processed (i.e., the first object a_obj), it is necessary to create an event class that inherits from the event delegate class. The event delegate class is the EventHandler class, and the event class to be processed inherits from the EventHandler class, using EventHandler as its parent class. Then, the event handling function is overridden in the event class to be processed, specifically the handleEvent function. The handleEvent function is a callback function; by overriding the handleEvent function, the event handling action is redefined so that the received event (Event) can be processed within the handleEvent function.

[0095] The second creation unit 12 is used to create an object of the event to be processed, thus obtaining the second object.

[0096] In this embodiment, an object of the event to be processed (Event) is created, and a second object e_obj is obtained, so that the second object e_obj is used as a parameter of the event sending function.

[0097] The event adding unit 13 is used to add the event to be processed to the event queue by using the second object as a parameter to call the event sending function of the first object; wherein the event queue includes multiple other events to be processed.

[0098] In this embodiment, the event sending function of the first object a_obj, namely the sendEvent function, is called, using the second object e_obj as a parameter, thereby passing the event to be processed from e_obj to a_obj. Specifically, the sendEvent function of the first object a_obj is called, passing the event to be processed to the EventHandler class, and then the event to be processed is added to the event queue EventQueue. The EventQueue includes multiple other events to be processed. By adding events to the EventQueue, events are processed uniformly, simplifying usage and reducing the learning curve. Furthermore, using the EventQueue to manage events optimizes the problem of poor event management, and the process of sending events is simpler, reducing execution time.

[0099] The event acquisition unit 14 is used to acquire an event sending signal and retrieve the corresponding pending event from the event queue according to the event sending signal as the target pending event.

[0100] In this embodiment, after adding the event to be processed to the event queue EventQueue, an event sending signal signalSendEvent is sent. The event sending signal signalSendEvent is then obtained, and the corresponding event to be processed is retrieved from the event queue according to the event sending signal signalSendEvent. The retrieved event to be processed is then used as the target event to be processed.

[0101] In one embodiment, the event acquisition unit 14 is specifically used for:

[0102] Obtain the target slot function and target event ID number corresponding to the event sending signal;

[0103] The target slot function retrieves the corresponding pending event from the event queue based on the target event ID, and uses the retrieved pending event as the target pending event.

[0104] In this embodiment, when a signal is emitted, the slot associated with that signal is executed; the slot is a function that responds to the signal. After adding the event to be processed (Event) to the event queue (EventQueue), an event sending signal (signalSendEvent) is emitted. This signal contains the target event ID (i.e., the parameter Event ID), which is used to retrieve the corresponding event to be processed from the event queue (EventQueue). The signal sends the target event ID to the corresponding target slot function (slotSendEvent). The target slot function (slotSendEvent) then receives the target event ID and uses it as a parameter to execute the target slot function. Based on the target event ID, the corresponding event to be processed is retrieved from the event queue (EventQueue), and this retrieved event is used as the target event to be processed. This combination of signals and slot functions allows for the rapid retrieval of the corresponding event to be processed from the event queue (EventQueue).

[0105] The timed start unit 15 is used to start a timer according to the delay duration in the target pending event, and save the timer ID number of the timer to the pending event corresponding to the target pending event in the event queue, so as to update the pending event with the timer ID number stored in the event queue to a delayed processing event.

[0106] In this embodiment, passing an event from one object to another sometimes requires delaying the processing of a specified event. Existing technologies using QT's API to send delayed events require implementing this through a loop. However, this invention, by starting a timer based on the delay duration in the target pending event, allows for more precise delays by directly specifying the required delay time. Simultaneously, the timer ID is saved to the corresponding pending event in the EventQueue. This updates the pending event in the EventQueue with the timer ID as a delayed processing event, ensuring that when the timer reaches the delay duration of the target pending event, the corresponding delayed processing event can be retrieved from the EventQueue based on the timer ID. This allows QT event passing to be used as a timer, optimizing the issues of QT timers not having parameters and parameter management.

[0107] In one embodiment, the timed start unit 15 is specifically used for:

[0108] Using the delay duration in the target event to be processed as a parameter for calling the first preset function, the timer is started and the timer ID number of the timer is returned; wherein, the first preset function is the Qobject::startTimer function;

[0109] The timer ID number is saved to the pending event corresponding to the target pending event in the event queue, so as to update the pending event with the timer ID number in the event queue to a delayed processing event.

[0110] In this embodiment, a timer is started by calling the `Qobject::startTimer` function. The function parameter is in milliseconds, representing the set duration, and returns a unique timer identifier. Specifically, using the delay duration in the target event as the parameter for calling `Qobject::startTimer` (e.g., if the delay duration in the target event is 15 seconds, then 15000 is used as the parameter), a timer with the set delay duration is started, and its timer ID is returned. Simultaneously, the timer ID is saved to the corresponding event in the `EventQueue`. This allows direct specification of the delay time for event execution, enabling the use of QT event propagation as a timer, thus optimizing the issues of QT timers not having parameters and parameter management.

[0111] The delay processing unit 16 is used to execute a timer event function to retrieve the delay processing event from the event queue according to the timer ID number.

[0112] In this embodiment, a timer event function is executed, which is the `timerEvent` function. When the timer reaches the delay duration of the target event to be processed, the `timerEvent` function will be entered to perform the necessary operations, retrieving the delayed processing event from the event queue `EventQueue` according to the timer ID number.

[0113] In one embodiment, the QT event transmission device further includes:

[0114] The first deletion unit is configured to delete the delayed processing event from the event queue if it is determined that the delayed processing event has not been deleted from the event queue.

[0115] In this embodiment, if a delayed event can be retrieved from the EventQueue based on the timer ID, it means that the event has not been deleted from the EventQueue within the specified delay time required for its execution. Therefore, after retrieving the delayed event from the EventQueue based on the timer ID, the delayed event is deleted from the EventQueue. Deleting the delayed event from the EventQueue saves storage space and facilitates the addition of new events.

[0116] In one embodiment, the QT event transmission device further includes:

[0117] The process termination unit is used to terminate the process if it is determined that the delayed processing event has not been successfully obtained.

[0118] In this embodiment, if the delayed processing event cannot be successfully retrieved from the event queue EventQueue based on the timer ID, it means that the delayed processing event has been deleted from the event queue EventQueue within the delay time. Since the delayed processing event does not need to be processed, the termination step is executed to end the process.

[0119] The event handling unit 17 is used to process the delayed processing event using a rewritten event handling function if it is determined that the delayed processing event has been successfully obtained.

[0120] In this embodiment, if a delayed processing event can be obtained from the event queue EventQueue based on the timer ID number, and it is determined that the delayed processing event has been successfully obtained, then the overridden event handling function is used to process the delayed processing event, that is, the handleEvent function is called to process the delayed processing event.

[0121] In one embodiment, the QT event transmission device further includes:

[0122] The second deletion unit is used to delete the delayed processing event from local storage.

[0123] In this embodiment, after calling the `handleEvent` function to process the delayed event, the delayed event is deleted from local storage to reduce local storage usage and improve system speed. Additionally, a deletion completion message can be generated and displayed after deleting the delayed event from local storage.

[0124] This invention provides a QT event passing device that enables unified event processing, simplifies usage, and reduces learning costs. Furthermore, the use of an EventQueue to manage events optimizes event management, and the process of sending events is more concise, reducing execution time. This invention optimizes QT event passing, featuring the ability to specify the delay time for event execution, improved event management, faster execution speed, cross-thread event passing, and the ability to be used as a timer.

[0125] The above QT event passing method can be implemented as a computer program, which can be used in, for example... Figure 3 It runs on the computer device shown.

[0126] Please see Figure 3 , Figure 3 This is a schematic block diagram of a computer device provided in an embodiment of the present invention. The computer device may be a terminal, such as a personal computer, tablet computer, smartphone, personal digital assistant (PDA), game console, interactive network television (IPTV), smart wearable device, etc.

[0127] The computer device 500 includes a processor 502, a memory, and a network interface 505 connected via a device bus 501, wherein the memory may include a storage medium 503 and internal memory 504.

[0128] The storage medium 503 can store the operating device 5031 and the computer program 5032. When the computer program 5032 is executed, it causes the processor 502 to execute the QT event passing method.

[0129] The processor 502 provides computing and control capabilities to support the operation of the entire computer device 500.

[0130] The internal memory 504 provides an environment for the execution of the computer program 5032 in the storage medium 503. When the computer program 5032 is executed by the processor 502, the processor 502 can execute the QT event passing method.

[0131] This network interface 505 is used for network communication, such as providing data transmission. Those skilled in the art will understand that... Figure 3 The structure shown is merely a block diagram of a portion of the structure related to the present invention and does not constitute a limitation on the computer device 500 to which the present invention is applied. The specific computer device 500 may include more or fewer components than shown in the figure, or combine certain components, or have different component arrangements.

[0132] The processor 502 is used to run a computer program 5032 stored in a memory to implement the QT event transmission method disclosed in this embodiment of the invention.

[0133] Those skilled in the art will understand that Figure 3 The embodiments of the computer device shown do not constitute a limitation on the specific configuration of the computer device. In other embodiments, the computer device may include more or fewer components than illustrated, or combine certain components, or have different component arrangements. For example, in some embodiments, the computer device may include only memory and a processor. In such embodiments, the structure and function of the memory and processor are different from those shown. Figure 3 The embodiments shown are consistent and will not be repeated here.

[0134] It should be understood that, in this embodiment of the invention, the processor 502 may be a Central Processing Unit (CPU), or it may be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor.

[0135] In another embodiment of the present invention, a computer-readable storage medium is provided. This computer-readable storage medium may be a non-volatile computer-readable storage medium or a volatile computer-readable storage medium. The computer-readable storage medium stores a computer program, wherein the computer program, when executed by a processor, implements the QT event passing method disclosed in the embodiments of the present invention.

[0136] Those skilled in the art will readily understand that, for the sake of convenience and brevity, the specific working processes of the devices, apparatuses, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here. Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this invention.

[0137] In the embodiments provided by this invention, it should be understood that the disclosed devices, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative. For instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. Units with the same function may be grouped into one unit. For example, multiple units or components may be combined or integrated into another device, or some features may be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed may be indirect coupling or communication connection through some interfaces, devices, or units, or may be electrical, mechanical, or other forms of connection.

[0138] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of the embodiments of the present invention, depending on actual needs.

[0139] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0140] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, a backend server, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), magnetic disks, or optical disks.

[0141] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in the present invention, and these modifications or substitutions should all be covered within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.

Claims

1. A QT event passing method, characterized in that, include: Create an object of the event class to be processed, and obtain the first object; Create an object of the event to be processed, and obtain a second object; Using the second object as a parameter to call the event sending function of the first object, the event to be processed is added to the event queue; wherein, the event queue includes multiple other events to be processed; Obtain an event sending signal, and retrieve the corresponding pending event from the event queue based on the event sending signal as the target pending event; A timer is started based on the delay duration in the target pending event, and the timer ID number of the timer is saved to the pending event corresponding to the target pending event in the event queue, so as to update the pending event in the event queue that has the timer ID number saved to a delayed processing event; Execute the timer event function to retrieve the delayed processing event from the event queue based on the timer ID number; If the delayed processing event is successfully obtained, the delayed processing event is processed using the overridden event handling function.

2. The QT event transmission method according to claim 1, characterized in that, The step of obtaining an event sending signal and retrieving the corresponding pending event from the event queue based on the event sending signal as the target pending event includes: Obtain the target slot function and target event ID number corresponding to the event sending signal; The target slot function retrieves the corresponding pending event from the event queue based on the target event ID, and uses the retrieved pending event as the target pending event.

3. The QT event transmission method according to claim 1, characterized in that, The step of starting a timer based on the delay duration in the target pending event and saving the timer ID to the pending event corresponding to the target pending event in the event queue, so as to update the pending event in the event queue with the timer ID as a delayed processing event, includes: Using the delay duration in the target event to be processed as a parameter for calling the first preset function, the timer is started and the timer ID number of the timer is returned; wherein, the first preset function is the Qobject::startTimer function; The timer ID number is saved to the pending event corresponding to the target pending event in the event queue, so as to update the pending event with the timer ID number in the event queue to a delayed processing event.

4. The QT event transmission method according to claim 3, characterized in that, After retrieving the delayed processing event from the event queue based on the timer ID number in the execution timer event function, the method further includes: If it is determined that the delayed processing event has not been deleted from the event queue, then the delayed processing event is deleted from the event queue.

5. The QT event transmission method according to claim 1, characterized in that, After determining that the delayed processing event has been successfully obtained, and then processing the delayed processing event using the overridden event handling function, the method further includes: Delete the delayed processing event from local storage.

6. The QT event transmission method according to claim 1, characterized in that, Before creating the object of the event class to be processed and obtaining the first object, the process also includes: Create the event class to be processed that inherits from the event delegate class, and override the event handling function in the event class to be processed.

7. The QT event transmission method according to claim 1, characterized in that, After retrieving the delayed processing event from the event queue based on the timer ID number in the execution timer event function, the method further includes: If it is determined that the delayed processing event was not successfully obtained, the process ends.

8. A QT event transmission device, characterized in that, include: The first creation unit is used to create an object of the event class to be processed, thus obtaining the first object; The second creation unit is used to create an object of the event to be processed, thus obtaining a second object; An event adding unit is used to add the event to be processed to an event queue by using the second object as a parameter to call the event sending function of the first object; wherein the event queue includes multiple other events to be processed; An event acquisition unit is used to acquire an event sending signal and, based on the event sending signal, retrieve the corresponding event to be processed from the event queue as the target event to be processed. The timed start unit is used to start a timer according to the delay duration in the target pending event, and save the timer ID number of the timer to the pending event corresponding to the target pending event in the event queue, so as to update the pending event with the timer ID number stored in the event queue to a delayed processing event; The delay processing unit is used to execute a timer event function to retrieve the delay processing event from the event queue according to the timer ID number; An event handling unit is used to process the delayed processing event using a rewritten event handling function if it is determined that the delayed processing event has been successfully obtained.

9. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the QT event passing method as described in any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, causes the processor to perform the QT event passing method as described in any one of claims 1 to 7.