Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. CWND to QWidget* => QWindow::fromWinId(), access violation error
Forum Updated to NodeBB v4.3 + New Features

CWND to QWidget* => QWindow::fromWinId(), access violation error

Scheduled Pinned Locked Moved Unsolved Installation and Deployment
4 Posts 2 Posters 630 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    EmmanuelC
    wrote on last edited by EmmanuelC
    #1

    Hello,
    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?

    Thank you,

    Emmanuel

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Did you check that the values you are getting are valid ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • E Offline
        E Offline
        EmmanuelC
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved