Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. The Lounge
  4. can't close the Qdialog
Qt 6.11 is out! See what's new in the release blog

can't close the Qdialog

Scheduled Pinned Locked Moved Solved The Lounge
2 Posts 2 Posters 1.7k 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.
  • F Offline
    F Offline
    fatemehkarimi
    wrote on last edited by
    #1

    hi, everyone.
    I have a class A which is a QDialog. in its constructor, it must read something from a file and if the file is not opened, the QDialog must be closed. I used

    this->close();
    

    but it doesn't work. what should I do???
    thank you very much

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      In the constructor the dialog is not even shown yet, so there's nothing to close.

      Usually with dialogs you have a code like this:

      SomeDialog dialog;
      dialog.exec();  //exec calls show() internally
      

      so if you want to prevent it from showing you can do something like this:

      SomeDialog dialog;
      if (dialog.isInitialized())
          dialog.exec();
      

      where isInitialized() would return true or false depending on what the constructor did.

      1 Reply Last reply
      3

      • Login

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