CWND to QWidget* => QWindow::fromWinId(), access violation error
EmmanuelC last edited by EmmanuelC
I'm using MFC to build a GUI , I recently integrated Qt5.12 library in my project. I need to connect a CWND pointer to QWidget pointer. To do so, I refered to this post : https://forum.qt.io/topic/76525/cwnd-to-qwidget
But I am getting an eccess violation error when I call QWindow::fromWinId() function.
My code is:
CWnd* cwnd= GetDlgItem(IDC_STATIC);
HWND hWnd = cwnd->GetSafeHwnd();
WId externalWindow = (WId)hWnd;
QWindow *myWindow = QWindow::fromWinId(externalWindow);
Does anyone know why I could get this error and how to fix it?
Hi and welcome to devnet,
Did you check that the values you are getting are valid ?
EmmanuelC last edited by
Thank you for your help!
I have checked if the HWND was valid with IsWindow(hWnd);
But I don't really know how to check if the WId is valid, but I can say that it's not a null value.
Sorry, I don't remember that one.
However, I did just remember that there might be something useful for you: the QtWinMigrate module. It might allow you to build what you need.
Hope it helps