Two interesting questions have been encountered recently. Here we will summarize:
1: In QT for Symbian, when the program runs: If you directly switch it to the background, the program will crash. To solve this problem, we need to first intercept the program and switch to the background event itself. I tried many methods, and the following method is more effective:
Mainwindow: mainwindow (qwidget * parent, qapplication * A): qwidget (parent)
{
This-> setfocuspolicy (QT: wheelfocus );
A-> installeventfilter (this );
Iapp =;
}
Bool mainwindow: eventfilter (qobject * OBJ, qevent * event)
{
Qfocusevent * focusevent = static_cast <qfocusevent *> (event );
If (OBJ = iapp)
{
If (Event-> type () =Qevent: focusout)
{
Rlog: log (_ L ("focusoutevent "));
Return true;
}
Else
{
Return false;
}
}
Else
{
Return qwidget: eventfilter (OBJ, event );
}
}
By logging, we can see that when the program switches from the foreground to the Background: The focusoutevent is displayed in the log to achieve our goal.
That is, we use the qapplication object to detect the focusout event. Note: Set setfocuspolicy () for the main window ().
2: Build a project bug with colleagues. When you click an item, the system will jump out of another window. But I don't know why, it will jump out of two identical windows.
Later, I caught up and found that we implemented it by sending a signal when calling this window, and realized the display of this window in its slot. However: We only sent this signal once. Finally, the problem lies in the connect function.
For the same pair of signal slots, if they connect several times, the number of times the slot executes when the same pair of signal is sent! That is, the number of Slot executions depends not only on the number of signal sends, but also on the number of declarations of the connect function! Our bug is that the connect function is declared twice in different files, so the slot is called twice.
For this problem, we need to check the number of declarations of the connect function. There are good solutions in qt4.6 or later versions, as follows:
Qo qbject: connect (const qobject *Sender, Const char *Signal, Const qobject *Cycler, Const char *Method, QT: connectiontypeType= QT: autoconnection)
You only need to set the last parameter to QT: uniqueconnection (this function declares that the signal slot is connected only once. If there is already a connection, the number of times does not take effect ). For qt4.5, I have not found a good solution. This parameter cannot be used for the same program in version 4.5, but can be used in version 4.6. We can use version macros to differentiate the program. That is, the qt_version macro.
If (qt_version> = 0x040600)
{}
Else
{}
3: some common debugging methods of QT, such as qfatal, qwarnning, qcritial, and q_assert. qfatal and q_assert will cause errors in the program after debugging and fail to run properly.
Statement
Lower