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. Close / Stop MDIChild in its constructor
Forum Updated to NodeBB v4.3 + New Features

Close / Stop MDIChild in its constructor

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 333 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.
  • P Offline
    P Offline
    pixbyte
    wrote on last edited by
    #1

    I want to avoid to see empty data tables in my app. So I want to stop MDIChild creation while it is created.
    As sample:

    MdiChildDiskInfo::MdiChildDiskInfo(QWidget* parent, const QString &device)
        :strBurnDrive(device){
          setAttribute(Qt::WA_DeleteOnClose);
    
          readDiskInfo();
    
    }
    
    void MdiChildDiskInfo::readDiskInfo()
    {
       int nError = 0;
       .....
       if( nError == 1 ) this->parentWidget()->close();
    }
    

    The problem here is, if I run this code the whole app is closed. Without parentWidget() it leaves empty dialogs. So how can I programmatically stop MDIChild creation?

    JonBJ 1 Reply Last reply
    0
    • P pixbyte

      I want to avoid to see empty data tables in my app. So I want to stop MDIChild creation while it is created.
      As sample:

      MdiChildDiskInfo::MdiChildDiskInfo(QWidget* parent, const QString &device)
          :strBurnDrive(device){
            setAttribute(Qt::WA_DeleteOnClose);
      
            readDiskInfo();
      
      }
      
      void MdiChildDiskInfo::readDiskInfo()
      {
         int nError = 0;
         .....
         if( nError == 1 ) this->parentWidget()->close();
      }
      

      The problem here is, if I run this code the whole app is closed. Without parentWidget() it leaves empty dialogs. So how can I programmatically stop MDIChild creation?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @pixbyte
      What "dialogs", there are no dialogs here? The code should probably be one of

      if( nError == 1 ) this->close();
      if( nError == 1 ) this->hide();
      

      Maybe it does not like you closing/hiding from the constructor, I don't know. Temporarily try it from elsewhere to test.

      You might also want to read e.g. https://www.qtcentre.org/threads/12409-Close-a-QMdiSubwindow . I'm not sure if it relates to what you see.

      1 Reply Last reply
      2
      • P Offline
        P Offline
        pixbyte
        wrote on last edited by
        #3

        Dialog or widgets...I think everyone knows what I mean.

        mrjjM 1 Reply Last reply
        0
        • P pixbyte

          Dialog or widgets...I think everyone knows what I mean.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          @pixbyte said in Close / Stop MDIChild in its constructor:

          Dialog or widgets...I think everyone knows what I mean.

          Yep, but for dialogs, there are Accept and Reject etc so in some use cases its really not the same :)
          Anyway

          if whole application closes, please try setting
          setQuitOnLastWindowClosed(false); on the application.
          https://doc.qt.io/qt-5/qguiapplication.html#quitOnLastWindowClosed-prop
          and see if that is what you are experiencing.

          That said, its really not super to try to cancel construction from within the ctor.
          However, it should work. ( i think)

          Is there a reason you cant just do

          bool MdiChildDiskInfo::readDiskInfo() .. <<< let it return a status if empty or not

          MdiChildDiskInfo * di = new MdiChildDiskInfo(..)
          if (! di->readDiskInfo() )
          di->DeleteLater(); // nothing to show get rid of it
          else
          di->show();
          (psudo code)

          1 Reply Last reply
          2

          • Login

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