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?
QtWS25 Last Chance

Closing an instance of QMainWindow?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 520 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on 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
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on 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

      SPlattenS 1 Reply Last reply
      2
      • SGaistS SGaist

        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.

        SPlattenS Offline
        SPlattenS Offline
        SPlatten
        wrote on 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
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

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

          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