Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. setGeometry crashes widget UI
Forum Updated to NodeBB v4.3 + New Features

setGeometry crashes widget UI

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 540 Views
  • 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.
  • W Offline
    W Offline
    Wille480
    wrote on last edited by
    #1

    Hello. I am trying to set my UI widget size to the size of a HWND handle obtained by FindWindowA function.
    I am able to retrieve the size from the HWND handle, and i can see that my UI widget window is set to the correct size right before it crashes, what is going on?..

    The UI window crashes right after it is shown and i do not know why.
    This is the code responsible for the size of the UI widget window:

    void DefuseHUD::WindowSize()
    {
        tagRECT *rect;
        GetWindowRect(FindWindowA(NULL, "Untitled - Notepad"), rect);
        this->setGeometry(rect->left, rect->top, rect->right - rect->left, rect->bottom - rec- 
        >top);
        this->setWindowState((windowState()));
    }
    

    and i call this function from another .cpp file like this:

        DefuseHUD *hud = new DefuseHUD(); // create instance of UI widget window.
        hud->WindowSize();
        hud->show();
    
    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

      You are accessing a dangling pointer.

      tagRECT rect;
      Q_ASSUME(GetWindowRect(FindWindowA(NULL, "Untitled - Notepad"), &rect));
      setGeometry(QRect(QPoint(rect.left, rect.top),QPoint(rect.right, rect.bottom)));
      

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      W 1 Reply Last reply
      3
      • VRoninV VRonin

        You are accessing a dangling pointer.

        tagRECT rect;
        Q_ASSUME(GetWindowRect(FindWindowA(NULL, "Untitled - Notepad"), &rect));
        setGeometry(QRect(QPoint(rect.left, rect.top),QPoint(rect.right, rect.bottom)));
        
        W Offline
        W Offline
        Wille480
        wrote on last edited by
        #3

        @vronin said in setGeometry crashes widget UI:

        n

        My god thanks .. So that was it all along i guess. Appriciate the help!

        1 Reply Last reply
        0

        • Login

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