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. Closing an instance of QMainWindow?
Forum Updated to NodeBB v4.3 + New Features

Closing an instance of QMainWindow?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 537 Views 3 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.
  • S Offline
    S Offline
    SPlatten
    wrote on 9 Feb 2021, 19:55 last edited by
    #1

    I want to programmatically close an instance of QMainWindow, I have a pointer to the widget associated with the window and I've tried calling the close function, it doesn't close the window and it remains visible.

    I've also tried casting the widget pointer to QMainWindow:

    QMainWindow* pobjWindow = static_cast<QMainWindow*>(pobjWidget);
    pobjWindow->close();
    

    I've single stepped this in the debugger to verify the pointer isn't nullptr, it doesn't close.

    Kind Regards,
    Sy

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 9 Feb 2021, 19:57 last edited by
      #2

      Hi,

      Maybe a silly question but: are you sure you are closing the instance you think you are closing ?

      By the way, you should rather use qobject_cast.

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

      S 1 Reply Last reply 9 Feb 2021, 19:59
      2
      • S SGaist
        9 Feb 2021, 19:57

        Hi,

        Maybe a silly question but: are you sure you are closing the instance you think you are closing ?

        By the way, you should rather use qobject_cast.

        S Offline
        S Offline
        SPlatten
        wrote on 9 Feb 2021, 19:59 last edited by
        #3

        @SGaist , I was just about to delete this post as you are perfectly correct, I was closing a different window.

        Kind Regards,
        Sy

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 9 Feb 2021, 20:00 last edited by
          #4

          Hi
          Please dont delete posts.
          Just flag it as solved.

          1 Reply Last reply
          1

          4/4

          9 Feb 2021, 20:00

          • Login

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