diff --git a/src/activeqt/control/qaxserverbase.cpp b/src/activeqt/control/qaxserverbase.cpp
index d0b0db4d77290e21a1ddcf894ab2524373f8a19c..daf2d771bc20dcd9af51a30b2663195b1ef1ce9e 100644
--- a/src/activeqt/control/qaxserverbase.cpp
+++ b/src/activeqt/control/qaxserverbase.cpp
@@ -1382,18 +1382,16 @@ LRESULT QT_WIN_CALLBACK QAxServerBase::ActiveXProc(HWND hWnd, UINT uMsg, WPARAM
 	    if(wParam) {
 	        that->internalCreate();
 	        if (!that->stayTopLevel) {
-                QWindow *widgetWindow = that->qt.widget->windowHandle();
                 // Set this property on window to pass the native handle to platform plugin,
                 // so that it can create the window with proper flags instead of thinking
                 // it is toplevel.
-                if (widgetWindow) {
-                    widgetWindow->setProperty("_q_embedded_native_parent_handle", WId(that->m_hWnd));
+                that->qt.widget->setProperty("_q_embedded_native_parent_handle", WId(that->m_hWnd));
 
+                if (QWindow *widgetWindow = that->qt.widget->windowHandle()) {
                     // If embedded widget is native, such as QGLWidget, it may have already created
                     // a window before now, probably as an undesired toplevel. In that case set the
                     // proper parent window and set the window frameless to position it correctly.
-                    if (widgetWindow
-                        && that->qt.widget->testAttribute(Qt::WA_WState_Created)
+                    if (that->qt.widget->testAttribute(Qt::WA_WState_Created)
                         && !that->qt.widget->isVisible()) {
                         HWND h = static_cast<HWND>(QGuiApplication::platformNativeInterface()->
                             nativeResourceForWindow("handle", widgetWindow));