QTimer::singleShot(0, ...) is just a complicated wrapper around
QMetaObject::invokeMethod(..., Qt::QueuedConnection). It does lots of
parameter checks, string parsing, and dynamic memory allocation before
finally calling QMetaObject::invokeMethod:

(Qt4) 
https://qt.gitorious.org/qt/qt/source/efce5d8361af41bf60dd16ce5aec65fe2fd84f88:src/corelib/kernel/qtimer.cpp#L349
(Qt5) 
https://qt.gitorious.org/qt/qtbase/source/2c1d597b653f16dc80a87d637c94213120f32d90:src/corelib/kernel/qtimer.cpp#L366
(Qt5) 
https://qt.gitorious.org/qt/qtbase/source/2c1d597b653f16dc80a87d637c94213120f32d90:src/corelib/kernel/qtimer.cpp#L388

Using QMetaObject::invokeMethod directly makes the code easier to
understand and avoids unnecessary overhead.

This patch is provided under the MIT license.

Index: src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp
===================================================================
--- src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp    (revision 55902)
+++ src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp    (working copy)
@@ -3843,7 +3843,7 @@
     if (!list.isEmpty())
     {
         m_ArgUrlList = list;
-        QTimer::singleShot(0, &vboxGlobal().selectorWnd(), 
SLOT(sltOpenUrls()));
+        QMetaObject::invokeMethod(&vboxGlobal().selectorWnd(), "sltOpenUrls", 
Qt::QueuedConnection);
     }
     return fResult;
 }
Index: src/VBox/Frontends/VirtualBox/src/net/UIUpdateManager.cpp
===================================================================
--- src/VBox/Frontends/VirtualBox/src/net/UIUpdateManager.cpp   (revision 55902)
+++ src/VBox/Frontends/VirtualBox/src/net/UIUpdateManager.cpp   (working copy)
@@ -447,7 +447,7 @@
 #ifdef VBOX_WITH_UPDATE_REQUEST
     /* Ask updater to check for the first time: */
     if (gEDataManager->applicationUpdateEnabled() && 
!vboxGlobal().isVMConsoleProcess())
-        QTimer::singleShot(0, this, SLOT(sltCheckIfUpdateIsNecessary()));
+        QMetaObject::invokeMethod(this, "sltCheckIfUpdateIsNecessary", 
Qt::QueuedConnection);
 #endif /* VBOX_WITH_UPDATE_REQUEST */
 }
 
Index: src/VBox/Frontends/VirtualBox/src/runtime/UIDnDMIMEData.cpp
===================================================================
--- src/VBox/Frontends/VirtualBox/src/runtime/UIDnDMIMEData.cpp (revision 55902)
+++ src/VBox/Frontends/VirtualBox/src/runtime/UIDnDMIMEData.cpp (working copy)
@@ -83,7 +83,7 @@
      *       and will take care of all the input handling. */
 #ifndef RT_OS_WINDOWS
     /* Install the event filter in a deferred way. */
-    QTimer::singleShot(0, this, SLOT(sltInstallEventFilter()));
+    QMetaObject::invokeMethod(this, "sltInstallEventFilter", 
Qt::QueuedConnection);
 #endif
 }
 
Index: src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp
===================================================================
--- src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp        
(revision 55902)
+++ src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp        
(working copy)
@@ -1525,7 +1525,7 @@
         pWidget->close();
         if (!pWidget->isHidden())
             pWidget->hide();
-        QTimer::singleShot(0, this, SLOT(sltClose()));
+        QMetaObject::invokeMethod(this, "sltClose", Qt::QueuedConnection);
         return;
     }
 
Index: src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.cpp
===================================================================
--- src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.cpp (revision 55902)
+++ src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.cpp (working copy)
@@ -1347,7 +1347,7 @@
                         QApplication::focusWidget()->clearFocus();
                         qApp->processEvents();
                     }
-                    QTimer::singleShot(0, this, SLOT(setFocus()));
+                    QMetaObject::invokeMethod(this, "setFocus", 
Qt::QueuedConnection);
                 }
                 break;
             }
Index: 
src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIKeyboardHandlerFullscreen.cpp
===================================================================
--- 
src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIKeyboardHandlerFullscreen.cpp
        (revision 55902)
+++ 
src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIKeyboardHandlerFullscreen.cpp
        (working copy)
@@ -62,7 +62,7 @@
                 if (isHostKeyPressed() && pKeyEvent->key() == 
gShortcutPool->shortcut(GUI_Input_MachineShortcuts, 
QString("PopupMenu")).sequence())
                 {
                     /* Post request to show popup-menu: */
-                    QTimer::singleShot(0, m_pMachineLogic, 
SLOT(sltInvokePopupMenu()));
+                    QMetaObject::invokeMethod(m_pMachineLogic, 
"sltInvokePopupMenu", Qt::QueuedConnection);
                     /* Filter-out this event: */
                     return true;
                 }
Index: 
src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineLogicFullscreen.cpp
===================================================================
--- 
src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineLogicFullscreen.cpp
   (revision 55902)
+++ 
src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineLogicFullscreen.cpp
   (working copy)
@@ -388,7 +388,7 @@
     if (m_pPopupMenu && !m_pPopupMenu->isEmpty())
     {
         m_pPopupMenu->popup(activeMachineWindow()->geometry().center());
-        QTimer::singleShot(0, m_pPopupMenu, SLOT(sltHighlightFirstAction()));
+        QMetaObject::invokeMethod(m_pPopupMenu, "sltHighlightFirstAction", 
Qt::QueuedConnection);
     }
 }
 
Index: 
src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineViewFullscreen.cpp
===================================================================
--- 
src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineViewFullscreen.cpp
    (revision 55902)
+++ 
src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineViewFullscreen.cpp
    (working copy)
@@ -89,7 +89,7 @@
                 setMaxGuestSize();
                 /* And resize guest to that size: */
                 if (m_bIsGuestAutoresizeEnabled && 
uisession()->isGuestSupportsGraphics())
-                    QTimer::singleShot(0, this, SLOT(sltPerformGuestResize()));
+                    QMetaObject::invokeMethod(this, "sltPerformGuestResize", 
Qt::QueuedConnection);
                 break;
             }
             default:
Index: 
src/VBox/Frontends/VirtualBox/src/runtime/normal/UIKeyboardHandlerNormal.cpp
===================================================================
--- 
src/VBox/Frontends/VirtualBox/src/runtime/normal/UIKeyboardHandlerNormal.cpp    
    (revision 55902)
+++ 
src/VBox/Frontends/VirtualBox/src/runtime/normal/UIKeyboardHandlerNormal.cpp    
    (working copy)
@@ -100,7 +100,7 @@
                         else
                         {
                             /* Post request to show popup-menu: */
-                            QTimer::singleShot(0, m_pMachineLogic, 
SLOT(sltInvokePopupMenu()));
+                            QMetaObject::invokeMethod(m_pMachineLogic, 
"sltInvokePopupMenu", Qt::QueuedConnection);
                         }
                         /* Filter-out this event: */
                         return true;
Index: src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineLogicNormal.cpp
===================================================================
--- src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineLogicNormal.cpp   
(revision 55902)
+++ src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineLogicNormal.cpp   
(working copy)
@@ -106,7 +106,7 @@
     if (m_pPopupMenu && !m_pPopupMenu->isEmpty())
     {
         m_pPopupMenu->popup(activeMachineWindow()->geometry().center());
-        QTimer::singleShot(0, m_pPopupMenu, SLOT(sltHighlightFirstAction()));
+        QMetaObject::invokeMethod(m_pPopupMenu, "sltHighlightFirstAction", 
Qt::QueuedConnection);
     }
 }
 #endif /* RT_OS_DARWIN */
Index: 
src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineWindowNormal.cpp
===================================================================
--- src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineWindowNormal.cpp  
(revision 55902)
+++ src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineWindowNormal.cpp  
(working copy)
@@ -383,7 +383,7 @@
 
         /* Normalize to the optimal size: */
 #ifdef Q_WS_X11
-        QTimer::singleShot(0, this, SLOT(sltNormalizeGeometry()));
+        QMetaObject::invokeMethod(this, "sltNormalizeGeometry", 
Qt::QueuedConnection);
 #else /* !Q_WS_X11 */
         normalizeGeometry(true /* adjust position */);
 #endif /* !Q_WS_X11 */
Index: 
src/VBox/Frontends/VirtualBox/src/runtime/scale/UIKeyboardHandlerScale.cpp
===================================================================
--- src/VBox/Frontends/VirtualBox/src/runtime/scale/UIKeyboardHandlerScale.cpp  
(revision 55902)
+++ src/VBox/Frontends/VirtualBox/src/runtime/scale/UIKeyboardHandlerScale.cpp  
(working copy)
@@ -69,7 +69,7 @@
                 if (isHostKeyPressed() && pKeyEvent->key() == 
gShortcutPool->shortcut(GUI_Input_MachineShortcuts, 
QString("PopupMenu")).sequence())
                 {
                     /* Post request to show popup-menu: */
-                    QTimer::singleShot(0, m_pMachineLogic, 
SLOT(sltInvokePopupMenu()));
+                    QMetaObject::invokeMethod(m_pMachineLogic, 
"sltInvokePopupMenu", Qt::QueuedConnection);
                     /* Filter-out this event: */
                     return true;
                 }
Index: src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineLogicScale.cpp
===================================================================
--- src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineLogicScale.cpp     
(revision 55902)
+++ src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineLogicScale.cpp     
(working copy)
@@ -69,7 +69,7 @@
     if (m_pPopupMenu && !m_pPopupMenu->isEmpty())
     {
         m_pPopupMenu->popup(activeMachineWindow()->geometry().center());
-        QTimer::singleShot(0, m_pPopupMenu, SLOT(sltHighlightFirstAction()));
+        QMetaObject::invokeMethod(m_pPopupMenu, "sltHighlightFirstAction", 
Qt::QueuedConnection);
     }
 }
 #endif /* !Q_WS_MAC */
Index: 
src/VBox/Frontends/VirtualBox/src/runtime/seamless/UIKeyboardHandlerSeamless.cpp
===================================================================
--- 
src/VBox/Frontends/VirtualBox/src/runtime/seamless/UIKeyboardHandlerSeamless.cpp
    (revision 55902)
+++ 
src/VBox/Frontends/VirtualBox/src/runtime/seamless/UIKeyboardHandlerSeamless.cpp
    (working copy)
@@ -69,7 +69,7 @@
                 if (isHostKeyPressed() && pKeyEvent->key() == 
gShortcutPool->shortcut(GUI_Input_MachineShortcuts, 
QString("PopupMenu")).sequence())
                 {
                     /* Post request to show popup-menu: */
-                    QTimer::singleShot(0, m_pMachineLogic, 
SLOT(sltInvokePopupMenu()));
+                    QMetaObject::invokeMethod(m_pMachineLogic, 
"sltInvokePopupMenu", Qt::QueuedConnection);
                     /* Filter-out this event: */
                     return true;
                 }
Index: 
src/VBox/Frontends/VirtualBox/src/runtime/seamless/UIMachineLogicSeamless.cpp
===================================================================
--- 
src/VBox/Frontends/VirtualBox/src/runtime/seamless/UIMachineLogicSeamless.cpp   
    (revision 55902)
+++ 
src/VBox/Frontends/VirtualBox/src/runtime/seamless/UIMachineLogicSeamless.cpp   
    (working copy)
@@ -171,7 +171,7 @@
     if (m_pPopupMenu && !m_pPopupMenu->isEmpty())
     {
         m_pPopupMenu->popup(activeMachineWindow()->geometry().center());
-        QTimer::singleShot(0, m_pPopupMenu, SLOT(sltHighlightFirstAction()));
+        QMetaObject::invokeMethod(m_pPopupMenu, "sltHighlightFirstAction", 
Qt::QueuedConnection);
     }
 }
 #endif /* !Q_WS_MAC */
Index: 
src/VBox/Frontends/VirtualBox/src/runtime/seamless/UIMachineViewSeamless.cpp
===================================================================
--- 
src/VBox/Frontends/VirtualBox/src/runtime/seamless/UIMachineViewSeamless.cpp    
    (revision 55902)
+++ 
src/VBox/Frontends/VirtualBox/src/runtime/seamless/UIMachineViewSeamless.cpp    
    (working copy)
@@ -104,7 +104,7 @@
                 setMaxGuestSize();
                 /* And resize guest to that size: */
                 if (uisession()->isGuestSupportsGraphics())
-                    QTimer::singleShot(0, this, SLOT(sltPerformGuestResize()));
+                    QMetaObject::invokeMethod(this, "sltPerformGuestResize", 
Qt::QueuedConnection);
                 break;
             }
             default:
Index: src/VBox/Frontends/VirtualBox/src/selector/UISelectorWindow.cpp
===================================================================
--- src/VBox/Frontends/VirtualBox/src/selector/UISelectorWindow.cpp     
(revision 55902)
+++ src/VBox/Frontends/VirtualBox/src/selector/UISelectorWindow.cpp     
(working copy)
@@ -1109,7 +1109,7 @@
 {
     /* Make sure user warned about inaccessible medium(s)
      * even if enumeration had finished before selector window shown: */
-    QTimer::singleShot(0, this, SLOT(sltHandleMediumEnumerationFinish()));
+    QMetaObject::invokeMethod(this, "sltHandleMediumEnumerationFinish", 
Qt::QueuedConnection);
 }
 
 #ifdef Q_WS_MAC
Index: src/VBox/Frontends/VirtualBox/src/selector/UIVMDesktop.cpp
===================================================================
--- src/VBox/Frontends/VirtualBox/src/selector/UIVMDesktop.cpp  (revision 55902)
+++ src/VBox/Frontends/VirtualBox/src/selector/UIVMDesktop.cpp  (working copy)
@@ -258,7 +258,7 @@
     /* Cocoa stuff should be async...
      * Do not ask me why but otherwise
      * it conflicts with native handlers. */
-    QTimer::singleShot(0, this, SLOT(sltInit()));
+    QMetaObject::invokeMethod(this, "sltInit", Qt::QueuedConnection);
 #else /* !Q_WS_MAC */
     sltInit();
 #endif /* !Q_WS_MAC */
Index: 
src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsSF.cpp
===================================================================
--- src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsSF.cpp  
(revision 55902)
+++ src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsSF.cpp  
(working copy)
@@ -609,7 +609,7 @@
     connect (mTwFolders->header(), SIGNAL (sectionResized (int, int, int)), 
this, SLOT (adjustFields()));
 
     /* Adjusting size after all pending show events are processed. */
-    QTimer::singleShot (0, this, SLOT (adjustList()));
+    QMetaObject::invokeMethod (this, "adjustList", Qt::QueuedConnection);
 }
 
 SFTreeViewItem* UIMachineSettingsSF::root(UISharedFolderType sharedFolderType)
Index: src/VBox/Frontends/VirtualBox/src/widgets/VBoxFilePathSelectorWidget.cpp
===================================================================
--- src/VBox/Frontends/VirtualBox/src/widgets/VBoxFilePathSelectorWidget.cpp    
(revision 55902)
+++ src/VBox/Frontends/VirtualBox/src/widgets/VBoxFilePathSelectorWidget.cpp    
(working copy)
@@ -275,7 +275,7 @@
 bool VBoxFilePathSelectorWidget::eventFilter (QObject *aObj, QEvent *aEv)
 {
     if (mIsMouseAwaited && (aEv->type() == QEvent::MouseButtonPress))
-        QTimer::singleShot (0, this, SLOT (refreshText()));
+        QMetaObject::invokeMethod (this, "refreshText", Qt::QueuedConnection);
 
     return QIWithRetranslateUI<QComboBox>::eventFilter (aObj, aEv);
 }

_______________________________________________
vbox-dev mailing list
[email protected]
https://www.virtualbox.org/mailman/listinfo/vbox-dev

Reply via email to