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. MainWindow closed when child Widget Close invoked
Forum Updated to NodeBB v4.3 + New Features

MainWindow closed when child Widget Close invoked

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 4 Posters 1.6k Views 2 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.
  • M Offline
    M Offline
    mourad_bilog
    wrote on last edited by mourad_bilog
    #1

    Hello everybody,

    In my application I call a child QWidget to do some treatement and when finishing and closing it I want to hide the mainwindow. The problem is that when call closeEvent() from the child Widget, it close the application (the mainwindow).

    Code in the MainWindow:

    frmWindow::frmWindow(QWidget *parent) : QMainWindow(parent) // constructor
    
    connect(frOrdo, SIGNAL(minimiseTout()), this, SLOT(MinimiserTout())); // frOrdo is the child QWidget et MinimiseTout is a slot I invoke it
    
    void frmWindow::minimiserTout()
    {
    	// Cache la fenêtre (et appelle closeEvent()).
        hide();
    	
    	// Enlève l'indication que la fenêtre est minimisée
        setWindowState(windowState() & ~Qt::WindowMinimized);
    }
    

    and in the child QWidget, I've this :

    void frmOrdo::closeEvent(QCloseEvent *event)
    {
    event->accept();
    		emit changeOrdo();
    		
    		emit closeWindow();
    
    		emit minimiseTout();	 
    }
    

    the signal minimiseTout will be intercepted in the mainWindow and call the MinimiserTout function witch must hide the MainWindow but it's closed.

    Can anyone tell me where I'm wrong and how to proceed to resolve the problem

    raven-worxR 1 Reply Last reply
    0
    • M mourad_bilog

      Hello everybody,

      In my application I call a child QWidget to do some treatement and when finishing and closing it I want to hide the mainwindow. The problem is that when call closeEvent() from the child Widget, it close the application (the mainwindow).

      Code in the MainWindow:

      frmWindow::frmWindow(QWidget *parent) : QMainWindow(parent) // constructor
      
      connect(frOrdo, SIGNAL(minimiseTout()), this, SLOT(MinimiserTout())); // frOrdo is the child QWidget et MinimiseTout is a slot I invoke it
      
      void frmWindow::minimiserTout()
      {
      	// Cache la fenêtre (et appelle closeEvent()).
          hide();
      	
      	// Enlève l'indication que la fenêtre est minimisée
          setWindowState(windowState() & ~Qt::WindowMinimized);
      }
      

      and in the child QWidget, I've this :

      void frmOrdo::closeEvent(QCloseEvent *event)
      {
      event->accept();
      		emit changeOrdo();
      		
      		emit closeWindow();
      
      		emit minimiseTout();	 
      }
      

      the signal minimiseTout will be intercepted in the mainWindow and call the MinimiserTout function witch must hide the MainWindow but it's closed.

      Can anyone tell me where I'm wrong and how to proceed to resolve the problem

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @mourad_bilog

      1. hiding and minimizing doesn't work. Just use one of the 2 methods, not both. And i guess this is what confuses you. hide() makes the window "disappear" from the screen.
      hide();
      setWindowState(windowState() & ~Qt::WindowMinimized);
      
      1. what does emit closeWindow(); do just before the minimiseTout() signal emission?

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      2
      • M Offline
        M Offline
        mourad_bilog
        wrote on last edited by
        #3

        Thansk for your response.

        I've commented the

        setWindowState(windowState() & ~Qt::WindowMinimized);
        

        and closeWindow(); signal. In fact I've added to call a function witch will close the chid Widget. It's not used now.

        But calling hide only in the minimiserTout() function still closes the mainwindow.

        I don't know if it must do it ?

        1 Reply Last reply
        0
        • C Offline
          C Offline
          CroCo
          wrote on last edited by
          #4

          Add a signal in widget child. Instantiate an object for widget child as a member data in the mainwindow class. Now, connect the signal of the widget child inside the mainwindow with the hide() function which should belong to the mainwindow(). Now you can emit the signal any time.

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi,

            How are you using the frmOrdo class ?

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

            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