0
Qobject::d eletelater ()
Delete obj; destructor object
1
Qwidget::setvisible (BOOL)
Make widgets visible or invisible
2
Qwidget::sethidden (BOOL)
Vest number 1th.
3
Qwidget::show ()
Vest number 1th.
4
Qwidget::hide ()
Vest number 1th.
5
Qwidget::close ()
Determine whether to call 4th number No. 0, as appropriate
6
Qdialog::d One (int)
Always call number 4th, call number No. 0 as appropriate
7
Qdialog::accept ()
Vest number 6th.
8
Qdialog::reject ()
Vest number 6th.
Write in front
We know
Objects that are assigned to the heap (through new) are destroyed when they are deleted.
The object that is allocated in the stack when it leaves the scope is the destructor
In Qt, it is generally recommended that you create objects in the same way as new. Or, you can look at the delete from Qt.
Attention:
The next discussion in this article is to assume that you are using the object created by new.
Qobject
Let's start with the ancestors of the Qt class. Because Qobject does not involve the interface, the members only deal with the problem of destruction. In the context of the delete from Qt, we know that
Obj->deletelater ();
The Last Call is:
Delete obj;
Very simple, huh. So, the talk of this function (slightly)
Additionally: The destroyed signal is emitted when the object is refactored. Note that is the object of the destructor when this is a nonsense, but keep in mind.
Qwidget
setvisible
Hehe, show (), Hide (), setvisible (), Sethidden () These 4 functions let a person see dazzling. What to do?
Let's look at the code:
virtual void setvisible (bool visible);
inline void Sethidden (bool hidden) {setvisible (!hidden);}
inline void Show () {setvisible (true);}
inline void Hide () {setvisible (false);}
The code is clear: among these four things, only setvisible is independent, and the other three are its vests!
What is the role of setvisible? As the name implies, makes a widget visible or invisible.
Important: Invisible, the widget is not displayed on the interface, but does not mean that the object is being refactored!
Close
This function, manual in the fact is very detailed, very thorough. But it's not easy at first to try to figure it out.
First, when we call close directly (or click the Close button call), it generates the Qcloseevent event: (We can choose to accept or block it, and if we block the event, close will return directly and do nothing)
Source:
BOOL Qwidgetprivate::close_helper (Closemode mode)
{
...
Qcloseevent e;
if (mode = = closewithspontaneousevent)
Qapplication::sendspontaneousevent (q, &e);
Else
Qapplication::sendevent (q, &e);
if (!that.isnull () &&!e.isaccepted ()) {
data.is_closing = 0;
return false;
}
...
}
Second: If we accept the event (the default), she calls directly to the friend we mentioned earlier. (Kill from the interface)
Q->hide ();
Again: If we set the tag bit for it (delete it when off): see Old friends again? (Kill from memory)
if (Q->testattribute (Qt::wa_deleteonclose)) {
Q->setattribute (Qt::wa_deleteonclose, false);
Q->deletelater ();
}
Out of the question: Close or other code, but not related to this topic, is no longer involved.
Qdialog
Qdialog and Qwidget have more than 3 correlation functions for done, reject, and accept:
Take a look at the two vests first:
void Qdialog::accept ()
{
Done (Accepted);
}
void Qdialog::reject ()
{
Done (rejected);
}
Done
The done thing is similar to close: because it calls the Close_helper function called by close. Just unlike the close function, it always makes the widget invisible first. Then close operation, and finally transmit the signal according to the parameters
void Qdialog::d one (int r)
{
Q_d (Qdialog);
Hide ();
Setresult (R);
D->close_helper (qwidgetprivate::closenoevent);
Emit finished (r);
if (r = = Accepted)
Emit accepted ();
else if (r = = rejected)
Emit rejected ();
}
Note: The QDILAOG may contain an event loop, the event loop starts with Qdialog::exec (), and qdialog::setvisible (false) will be responsible for exiting the event loop, with its waistcoat hide ().
Qt Show,hide,setvisible,sethidden,close etc summary