Disclosure of Invention
The embodiment of the invention provides a modal dialog box processing method and device, and solves the technical problem that each modal dialog box is inoperable when a brother modal dialog box is popped up in the prior art.
In a first aspect, an embodiment of the present invention provides a modal dialog processing method, including:
if a related message for creating a new modal dialog box is received, acquiring the original modal dialog box and all father modal dialog boxes of the original modal dialog box, wherein the new modal dialog box is a brother dialog box of the original modal dialog box;
hiding the original modal dialog box and all parent modal dialog boxes of the original modal dialog box;
after the original modal dialog and all parent modal dialogs are hidden, opening and displaying the new modal dialog that has been created.
Optionally, after the opening and displaying the new modal dialog box that has been created, the method further includes:
if the closing message of the new modal dialog box is received, closing the new modal dialog box;
after the new modality dialog is closed, the original modality dialog and all parent modality dialogs of the original modality dialog are closed.
Optionally, the closing the original modal dialog and all parent modal dialogs of the original modal dialog includes:
closing the original modal dialog box;
and closing all the parent modal dialog boxes of the original modal dialog box in sequence according to the acquisition sequence of all the parent modal dialog boxes of the original modal dialog box.
Optionally, the original modal dialog box is an active modal dialog box currently located at the topmost layer;
the acquiring the original modal dialog box and all parent modal dialog boxes of the original modal dialog box comprises:
acquiring and saving the active modal dialog box;
acquiring all father modal dialog boxes of the active modal dialog boxes through the active modal dialog boxes;
and saving all the acquired parent modal dialog boxes of the active modal dialog box.
Optionally, hiding the original modal dialog and all parent modal dialogs of the original modal dialog includes:
calling a hidden function of the original modal dialog box to hide the original modal dialog box;
after the original modal dialog box is hidden, sequentially calling respective hiding functions of all parent modal dialog boxes of the original modal dialog box according to the acquiring sequence of all parent modal dialog boxes of the original modal dialog box so as to sequentially hide all parent modal dialog boxes of the original modal dialog box.
In a second aspect, an embodiment of the present invention provides a modal dialog processing apparatus, including:
a dialog box obtaining unit, configured to obtain the original modal dialog box and all parent modal dialog boxes of the original modal dialog box if a related message for creating a new modal dialog box is received, where the new modal dialog box is a sibling dialog box of the original modal dialog box;
a hiding unit, configured to hide the original modal dialog and all parent modal dialogs of the original modal dialog;
and the opening unit is used for opening and displaying the created new modal dialog box after the original modal dialog box and all the father modal dialog boxes are hidden.
Optionally, the apparatus further comprises:
the first closing unit is used for closing the new modal dialog box if the closing message of the new modal dialog box is received;
and the second closing unit is used for closing the original modal dialog box and all the parent modal dialog boxes of the original modal dialog box after the new modal dialog box is closed.
The second closing unit is specifically configured to: closing the original modal dialog box; according to the acquisition sequence of all the parent modal dialog boxes of the original modal dialog box, closing all the parent modal dialog boxes of the original modal dialog box in sequence;
the original modal dialog box is an active modal dialog box which is positioned at the topmost layer currently;
the dialog box obtaining unit is specifically configured to: acquiring and saving the active modal dialog box; acquiring all father modal dialog boxes of the active modal dialog boxes through the active modal dialog boxes; and saving all the acquired parent modal dialog boxes of the active modal dialog box.
Optionally, the hiding unit is specifically configured to:
calling a hidden function of the original modal dialog box to hide the original modal dialog box;
after the original modal dialog box is hidden, sequentially calling respective hiding functions of all parent modal dialog boxes of the original modal dialog box according to the acquiring sequence of all parent modal dialog boxes of the original modal dialog box so as to sequentially hide all parent modal dialog boxes of the original modal dialog box.
In a third aspect, the present invention provides a computer-readable storage medium, on which a computer program is stored, where the computer program is executed by a processor to implement the steps described in any one of the implementation manners in the first aspect.
In a fourth aspect, an embodiment of the present invention provides a computer device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, where the processor implements the steps described in any of the embodiments of the first aspect when executing the program.
One or more technical solutions provided in the embodiments of the present invention have at least the following technical effects or advantages:
if the related information for creating the new modal dialog box is received, acquiring the original modal dialog box and all father modal dialog boxes of the original modal dialog box, wherein the new modal dialog box is a brother dialog box of the original modal dialog box; hiding the original modal dialog box and all parent modal dialog boxes of the original modal dialog box; after the original modal dialog and all parent modal dialogs are hidden, the new modal dialog that has been created is opened and displayed. Therefore, before the new modal dialog box is opened, the dialog box which has no parent-child relationship with the new modal dialog box, namely the brother dialog box, is hidden but not closed, so that the display execution function of the original modal dialog box can not return at the moment, namely, a window closing message is not required to be sent to the currently displayed original modal dialog box, message blocking can not be caused, and the original modal dialog box object is not closed, so that the program is not destroyed, the technical problem that each modal dialog box is not operable when the brother modal dialog box is popped up is effectively solved, and the popped modal dialog box is ensured to be operable.
Detailed Description
The embodiment of the invention provides a modal dialog box processing method and a modal dialog box processing device, solves the technical problem that each modal dialog box is inoperable when a brother modal dialog box is popped up in the prior art, and solves the technical problems by adopting the technical scheme of the embodiment of the invention, and the general idea is as follows:
if the other sibling modal dialog currently displayed is closed before the new modal dialog is opened. Because the modal dialog is synchronously blocked, that is, the display function of the current modal dialog waits to return, and the window closing message needs to be sent when the synchronous display function returns, even if the closing message is sent to the current modal dialog immediately, the message is still blocked after the new modal dialog is opened. If the current modal dialog box is built on the heap through the new function, the delete is used for destroying when the dialog box is closed, and after the new modal dialog box is closed, the original modal dialog box returns to continue execution, but because the dialog box object is destroyed before, the program is crashed due to the memory problem; if the memory is not destroyed when the memory is closed, the memory may leak.
If the embodiment of the invention receives the related information for creating the new modal dialog box, the original modal dialog box and all father modal dialog boxes of the original modal dialog box are obtained, and the new modal dialog box is the brother dialog box of the original modal dialog box; hiding the original modal dialog box and all parent modal dialog boxes of the original modal dialog box; after the original modal dialog and all parent modal dialogs are hidden, the new modal dialog that has been created is opened and displayed.
Through the technical scheme, the dialog box which has no parent-child relationship with the new modal dialog box, namely the brother dialog box, can be hidden before the new modal dialog box is opened, and because the dialog box is just hidden but not closed, the display execution function of the original modal dialog box can not return at the moment, namely, the window closing message does not need to be sent to the currently displayed original modal dialog box, message blocking can not be caused, and because the original modal dialog box object is not closed, the dialog box is not destroyed, the program crash can not be caused, the technical problem that each modal dialog box is not operable when the brother modal dialog box is popped up is effectively solved, and the popped up modal dialog box is ensured to be operable.
In order to better understand the technical solution, the technical solution will be described in detail with reference to the drawings and the specific embodiments.
Referring to fig. 1, a modal dialog processing method according to an embodiment of the present invention includes the following steps:
s101, if relevant information for creating a new modal dialog box is received, acquiring the original modal dialog box and all parent modal dialog boxes of the original modal dialog box, wherein the new modal dialog box is a sibling dialog box of the original modal dialog box.
The new modal dialog box is a brother dialog box of the original modal dialog box, and the new modal dialog box is characterized in that no parent-child relationship exists between the new modal dialog box and the original modal dialog box.
Specifically, the related message may be: the receipt of the process of creating a new modal dialog causes the currently displayed original modal dialog to generate an abnormal signal, e.g., the logged-in user corresponding to the original modal dialog is squeezed out and a related signal is received. Specifically, a client program that needs to be authenticated by the server logs in using the account number, and then opens a setup window, which is a modal dialog. At this time, the login window of another client program uses the same account number to log in, if the subsequent login window is a modal dialog window, the subsequent login window and the setting window on the previous client program are brother dialog boxes, and at this time, the login user on the previous client program may be squeezed out and related information is prompted. Then step S101 is executed to acquire the original modal dialog box and all parent modal dialog boxes of the original modal dialog box. Specifically, a setting window on a previous client program and a parent window of the setting window are obtained.
It should be noted that, if the slot function connected to the relevant signal receives the relevant signal, for example, if the relevant signal extruded by the login user corresponding to the client program is received, the situation that a new modal dialog box needs to be displayed is processed in the slot function connected to the relevant signal, and then the subsequent steps S102 to S104 are specifically executed in the slot function connected to the relevant signal.
Specifically, the currently displayed original modal dialog box is the topmost active modal dialog box. Correspondingly, if the original modal dialog box and all parent modal dialog boxes of the original modal dialog box are obtained, S101 specifically includes the following steps:
first, step S1011 is executed: and acquiring and saving the active modal dialog box currently displayed at the topmost layer.
Specifically, if there is an active modality dialog currently displayed at the topmost layer, step S1012 is then performed, otherwise step S103 is performed.
In the specific implementation process, the QWIDGet type object of the modal window corresponding to the active modal dialog box displayed at the top layer at present is obtained through the QAPPLICATION. And judging whether the value of the QWIdget type object of the modal window is 0, if so, indicating that no active modal dialog box displayed at the topmost layer exists currently, and if not, indicating that the active modal dialog box displayed at the topmost layer exists currently. If there is an active modal dialog currently displayed at the top level, the modal window QWIdget type object of the active modal dialog currently displayed at the top level is saved.
Step S1012: all parent modal dialogs of an active modal dialog are obtained through the active modal dialog currently displayed at the topmost level.
Specifically, each parent modal dialog box of the original modal dialog box is sequentially acquired from near to far according to the parent-child relationship with the original modal dialog box.
In the specific implementation process, the acquiring of the parent modal dialog box comprises the following steps:
step 1, acquiring a parent window object corresponding to a parent modal dialog box of the active modal dialog box currently displayed at the topmost layer through a parent member function parent of a modal window QWIDGet type object of the active modal dialog box currently displayed at the topmost layer, and entering step 5 if the return value of the parent member function parent is 0, indicating that the active modal dialog box currently displayed at the topmost layer does not have the parent modal dialog box; if the return value of parent function parent is not 0, it indicates that the active modal dialog box currently displayed at the top layer, and then step 2 is entered.
It should be noted that the QWidget class is a base class of all user interface objects, all UI class objects on the Qt program are inherited by the QWidget class, and the QWidget class is inherited by the QObject class, wherein the parent window object of the active-mode dialog box previously displayed at the topmost layer is a QObject type object.
Step 2, judging whether the parent window object of the active modal dialog box displayed at the topmost layer is a window component or not through an isWidgetType member function of a QObject type, and if not, entering step 5; if yes, the parent window object of the active mode dialog box displayed at the topmost layer is forcedly converted into a QWIdget type object by the QObject type object, and then the step 3 is carried out.
Step 3, judging whether the father window object is a modal dialog box or not through the isomodal member function of the father window object which is the QObject type object, and entering step 5 if not; if yes, entering step 4;
and 4, storing the parent window object which is the QObject type object, acquiring a parent mode window directly related to the parent window object which is the QObject type object, and returning to the step 2.
Step 5, the loop is exited, whereby the active modality dialog and all parent modalities of the active modality dialog are acquired, and step S1013 is performed.
Step S1013: the retrieved active modality dialog and all parent modality dialogs of the active modality dialog are saved.
After step S101, step S102 is then performed: hiding the original modal dialog box and all parent modal dialog boxes of the original modal dialog box.
Specifically, the original modal dialog box is hidden first, and then all parent modal dialog boxes of the original modal dialog box are hidden, wherein the hiding sequence of the parent modal dialog boxes is the same as the acquiring sequence of the parent modal dialog boxes.
In the following, a specific embodiment of hiding the original modal dialog and all parent modal dialogs of the original modal dialog is given, which includes:
hiding the original modal dialog box by calling a hidden function hide of the original modal dialog box; after the original modal dialog box is hidden, according to the acquisition sequence of all the parent modal dialog boxes of the original modal dialog box, the respective hiding functions of all the parent modal dialog boxes are called in sequence, and therefore all the parent modal dialog boxes of the original modal dialog box are hidden in sequence.
After step S102, step S103 is then performed: after the original modal dialog and all parent modal dialogs are hidden, the new modal dialog that has been created is opened and displayed.
The synchronization function is called to open the new modal dialog box, and the calling of the synchronization function prevents the subsequent steps from being executed continuously, so that the subsequent steps are executed continuously until the displayed new modal dialog box is closed, for example, the step S104 is executed after the displayed new modal dialog box is closed.
Or after the displayed new modal dialog box is closed, the hidden original modal dialog box and the parent modal dialog box of the original modal dialog box can be displayed.
In conjunction with the foregoing embodiment, the present embodiment provides step S104 after the new modal dialog is opened and displayed, so that after the displayed new modal dialog is closed, the hidden original modal dialog and all parent dialogs of the original modal dialog are no longer displayed, thereby maintaining the consistency of the application.
Step S104, if the closing message of the new modal dialog box is received, closing the new modal dialog box; after the new modal dialog is closed, the original modal dialog and all parent modal dialogs of the original modal dialog are closed.
Specifically, the original modal dialog box is closed first, and then all parent modal dialog boxes of the original modal dialog box are closed, and the closing sequence of each parent modal dialog box is the same as the acquiring sequence of the parent modal dialog box.
In the specific implementation process, the process of closing the original modal dialog box and each parent modal dialog box of the original modal dialog box specifically includes: and closing the original modal dialog box, and after the original modal dialog box is in a closed state, closing all the parent modal dialog boxes of the original modal dialog box in sequence according to the acquisition sequence of all the parent modal dialog boxes of the original modal dialog box.
Specifically, the hidden original modal dialog boxes are closed by calling the close functions of the original modal dialog boxes, and then the close functions of the parent modal dialog boxes are sequentially called according to the acquisition sequence of the parent modal dialog boxes, so that the parent modal dialog boxes are sequentially closed.
According to the acquisition sequence of all the parent modal dialog boxes of the original modal dialog box, the mode of closing all the parent modal dialog boxes of the original modal dialog box in sequence avoids the situation that the parent window is destroyed and the child window still exists, and further avoids application program collapse caused by memory problems.
Based on the same inventive concept, an embodiment of the present invention provides a modal dialog processing apparatus, which is shown in fig. 2 and includes:
a dialogbox obtaining unit 201, configured to obtain the original modal dialog box and all parent modal dialog boxes of the original modal dialog box if a related message for creating a new modal dialog box is received, where the new modal dialog box is a sibling dialog box of the original modal dialog box;
ahiding unit 202, configured to hide the original modal dialog and all parent modal dialogs of the original modal dialog;
and theopening unit 203 is used for opening and displaying the created new modal dialog box after the original modal dialog box and all the parent modal dialog boxes are hidden.
In combination with the foregoing embodiment, in another embodiment, the apparatus further includes:
the first closing unit is used for closing the new modal dialog box if a closing message of the new modal dialog box is received;
and the second closing unit is used for closing the original modal dialog box and all the parent modal dialog boxes of the original modal dialog box after the new modal dialog box is closed.
The second closing unit is specifically configured to: closing the original modal dialog box; according to the acquisition sequence of all the parent modal dialog boxes of the original modal dialog box, closing all the parent modal dialog boxes of the original modal dialog box in sequence;
the original modal dialog box is an active modal dialog box at the topmost layer currently;
the dialogbox obtaining unit 201 is specifically configured to: acquiring and saving an active modal dialog box; acquiring all father modal dialog boxes of the active modal dialog boxes through the active modal dialog boxes; all parent modal dialogs of the retrieved active modal dialog are saved.
In an embodiment, thehiding unit 202 is specifically configured to:
calling a hidden function of the original modal dialog box to hide the original modal dialog box;
after the original modal dialog box is hidden, respective hiding functions of all the parent modal dialog boxes of the original modal dialog box are called in sequence according to the acquiring sequence of all the parent modal dialog boxes of the original modal dialog box, and the parent modal dialog boxes of the original modal dialog box are hidden in sequence.
The detailed implementation of the apparatus in the present embodiment and its various modifications can be understood by those skilled in the art, so that the detailed description of how the apparatus implements the modal dialog processing method embodiment of the present invention is not provided here. The scope of the present invention is intended to cover the apparatus used by those skilled in the art to implement the modal dialog processing method of the present invention.
Based on the same inventive concept, referring to fig. 3, an embodiment of the present invention provides a computer-readable storage medium 301, on which acomputer program 302 is stored, where theprogram 302, when executed by a processor, implements the steps of any of the foregoing modal dialog processing method embodiments.
Based on the same inventive concept, the embodiment of the present invention provides acomputer device 400, which is shown in fig. 4 and includes amemory 410, aprocessor 420, and acomputer program 411 stored in thememory 410 and running on theprocessor 420, wherein when theprocessor 420 executes thecomputer program 411, the steps of any embodiment of the modal dialog processing method embodiment are implemented.
One or more embodiments of the invention provide at least the following technical effects or advantages:
if the related message for creating the new modal dialog box is received, acquiring the original modal dialog box and all father modal dialog boxes of the original modal dialog box, wherein the new modal dialog box is a brother dialog box of the original modal dialog box; hiding the original modal dialog box and all parent modal dialog boxes of the original modal dialog box; after the original modal dialog and all parent modal dialogs are hidden, the new modal dialog that has been created is opened and displayed. Therefore, before the new modal dialog box is opened, the dialog box which has no parent-child relationship with the new modal dialog box, namely the brother dialog box, is hidden but not closed, so that the display execution function of the original modal dialog box can not return at the moment, namely, a window closing message is not required to be sent to the currently displayed original modal dialog box, message blocking can not be caused, and the original modal dialog box object is not closed, so that the program is not destroyed, the technical problem that each modal dialog box is not operable when the brother modal dialog box is popped up is effectively solved, and the popped modal dialog box is ensured to be operable.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, system, or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
While preferred embodiments of the present invention have been described, additional variations and modifications in those embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. Therefore, it is intended that the appended claims be interpreted as including preferred embodiments and all such alterations and modifications as fall within the scope of the invention.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present invention without departing from the spirit and scope of the invention. Thus, if such modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include such modifications and variations.