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. [SOLVED] Difference between QWidget::hide() and QWidget::close()
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Difference between QWidget::hide() and QWidget::close()

Scheduled Pinned Locked Moved General and Desktop
11 Posts 7 Posters 26.0k 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.
  • A Offline
    A Offline
    aekam
    wrote on last edited by
    #1

    Hello,
    I am little bit confused regarding difference between QWidget::hide() and QWidget::close().
    What exactly happens if "I close and show a widget" and "I hide and show a widget"

    If you take care of inches, you won't have to worry about miles... :)

    Q 1 Reply Last reply
    1
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      It's desribed quite clearly in "the documentation":http://qt-project.org/doc/qt-4.8/qwidget.html#close.

      ::hide() only makes the widget disappear. ::close() can even destroy it in some cases.

      (Z(:^

      1 Reply Last reply
      1
      • G Offline
        G Offline
        giesbert
        wrote on last edited by
        #3

        close and hide are two different things.
        Close is typically done, when you click the cross in the upper right corner. If a widget has the flag delete on close, it will be deleted afterwards.
        Hid just makes the widget hidden.

        Nokia Certified Qt Specialist.
        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

        1 Reply Last reply
        1
        • A Offline
          A Offline
          aekam
          wrote on last edited by
          #4

          bq. First it sends the widget a QCloseEvent. The widget is hidden if it accepts the close event. If it ignores the event, nothing happens. The default implementation of QWidget::closeEvent() accepts the close event.

          This is QWidget::close() detail, so default behavior is, whenever the ::close() is called, it simply hides the widget, right.?

          If you take care of inches, you won't have to worry about miles... :)

          1 Reply Last reply
          0
          • V Offline
            V Offline
            vittalonline
            wrote on last edited by
            #5

            hide : we can reuse or display again
            close : widget completely close.

            1 Reply Last reply
            1
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

              [quote author="aekam" date="1366881423"]This is QWidget::close() detail, so default behavior is, whenever the ::close() is called, it simply hides the widget, right.?[/quote]

              Read the whole description. The point is: it might just hide the widget on close(), but if your settings in code are different, it might delete it completely, or even close the whole application.

              If you need the widget later, use hide() or setVisible(false). If you need to destroy it, do it yourself. close() is to be used with care.

              (Z(:^

              1 Reply Last reply
              0
              • B Offline
                B Offline
                b1gsnak3
                wrote on last edited by
                #7

                The difference is that when you close the widget, if the Qt::WA_DeleteOnClose flag is set, the widget is deleted and any other data that it stored along with it... If not, the close method is a fancier way to say hide :)

                1 Reply Last reply
                0
                • B Offline
                  B Offline
                  b1gsnak3
                  wrote on last edited by
                  #8

                  also, if it is the only window open in your application it quits the application... so as sierdzio said:
                  [quote author="sierdzio" date="1366881775"]
                  If you need the widget later, use hide() or setVisible(false). If you need to destroy it, do it yourself. close() is to be used with care.[/quote]

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    aekam
                    wrote on last edited by
                    #9

                    Thank you all for information... :)

                    If you take care of inches, you won't have to worry about miles... :)

                    1 Reply Last reply
                    0
                    • A aekam

                      Hello,
                      I am little bit confused regarding difference between QWidget::hide() and QWidget::close().
                      What exactly happens if "I close and show a widget" and "I hide and show a widget"

                      Q Offline
                      Q Offline
                      QtTester
                      wrote on last edited by
                      #10

                      @aekam
                      usually:
                      hide() = close()
                      but:
                      hide() != close() + deleteLater()
                      I think.

                      JonBJ 1 Reply Last reply
                      0
                      • Q QtTester

                        @aekam
                        usually:
                        hide() = close()
                        but:
                        hide() != close() + deleteLater()
                        I think.

                        JonBJ Online
                        JonBJ Online
                        JonB
                        wrote on last edited by
                        #11

                        @QtTester said in [SOLVED] Difference between QWidget::hide() and QWidget::close():

                        usually:
                        hide() = close()

                        I don't know why you are replying to a thread last updated a decade ago! But as stated in the answers above, hide() does not close() a widget....

                        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