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. Windows cannot terminate process when i'm shutting down or restarting computer
Forum Updated to NodeBB v4.3 + New Features

Windows cannot terminate process when i'm shutting down or restarting computer

Scheduled Pinned Locked Moved General and Desktop
11 Posts 3 Posters 3.9k 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
    pjeroo
    wrote on last edited by
    #1

    I have a clear project. There is only one slot onbuttonclick and there is just one command: this->hide(); When i push on it and form is hiding i cannot shutdown or restart my windows until i close the app or show form. Can you help me with it, please? Qt 5.2.1 Static

    Sorry for my bad english.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      code_fodder
      wrote on last edited by
      #2

      When you say you can't shutdown... do you mean the desktop buttons / icons / windows are non-responsive? or what is happening?

      Please show the code as well so we can see it :)

      1 Reply Last reply
      0
      • P Offline
        P Offline
        pjeroo
        wrote on last edited by
        #3

        mainwindow.cpp
        @#include "mainwindow.h"
        #include "ui_mainwindow.h"

        MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
        {
        ui->setupUi(this);
        }

        MainWindow::~MainWindow()
        {
        delete ui;
        }

        void MainWindow::on_pushButton_clicked()
        {
        this->hide();
        }@

        mainwindow.h
        @#ifndef MAINWINDOW_H
        #define MAINWINDOW_H

        #include <QMainWindow>

        namespace Ui {
        class MainWindow;
        }

        class MainWindow : public QMainWindow
        {
        Q_OBJECT

        public:
        explicit MainWindow(QWidget *parent = 0);
        ~MainWindow();

        private slots:
        void on_pushButton_clicked();

        private:
        Ui::MainWindow *ui;
        };

        #endif // MAINWINDOW_H@

        if application was started and hidded (this->hide) and i'm trying to shutdown or restart windows, nothing just happens. if i don't hide form and i'm trying to shutdown or restart windows, windows successful shutting down.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          gyll
          wrote on last edited by
          #4

          well, if you hide the only one form in a GUI application then there's no way left for you to close the application, so the process keeps running and windows will complain about this when you try to shut down (it should eventually ask you to terminate the process manually when you shut down). Try looking in your windows task manager and you'll probably find your application running there (and you can force-kill the process from there).

          The bottom line is, you should never close all the windows of an application if you want to be able to shut down its associated process(es); this is however a way to have a window-less application running as a background process.

          1 Reply Last reply
          0
          • P Offline
            P Offline
            pjeroo
            wrote on last edited by
            #5

            so, if i hide form. there is no way to catch WM_CLOSE event from windows?

            1 Reply Last reply
            0
            • C Offline
              C Offline
              code_fodder
              wrote on last edited by
              #6

              You can catch the events of course (hiding does not stop your program/app from running.

              But you may have to code it up! - you have to write some sort of event handler to catch the close event.

              In your mainwindow you can implement the function:
              @
              bool QObject::event(QEvent * e) [virtual]
              @

              And handle all events manually - i.e. look for the window close event in there. Look at the documentation for some examples...

              1 Reply Last reply
              0
              • C Offline
                C Offline
                code_fodder
                wrote on last edited by
                #7

                Had a quick look around, and I think you need to catch the

                @
                void QCoreApplication::aboutToQuit() [signal]
                @

                signal, so make a connection with this to some slot of your own in MainWindow to close your app.

                1 Reply Last reply
                0
                • P Offline
                  P Offline
                  pjeroo
                  wrote on last edited by
                  #8

                  @#include "mainwindow.h"
                  #include "ui_mainwindow.h"

                  MainWindow::MainWindow(QWidget *parent) :
                  QMainWindow(parent),
                  ui(new Ui::MainWindow)
                  {
                  ui->setupUi(this);
                  connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(Test()));
                  }

                  MainWindow::~MainWindow()
                  {
                  delete ui;
                  }

                  void MainWindow::on_pushButton_clicked()
                  {
                  this->hide();
                  }

                  void MainWindow::Test()
                  {
                  qApp->exit();
                  }@

                  i've changed my mainwindow class like that, but my Windows still don't want to shutdown.. all programs are closing, excluding my application

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    gyll
                    wrote on last edited by
                    #9

                    I don't know how to catch events in Qt, but WM_CLOSE will never reach an invisible window. I googled a little for WM_CLOSE, WM_QUIT, etc, and apparently there's a PeekMessage function which allows you to see if there's a WM_QUIT message sent to your app, see here http://stackoverflow.com/questions/3155782/what-is-the-difference-between-wm-quit-wm-close-and-wm-destroy-in-a-windows-pr . However, using these functions will obviously make your application not directly cross-platform, so you should probably wrap windows' PeekMessage in a function of your own which should have different platform-dependent implementations.

                    1 Reply Last reply
                    0
                    • C Offline
                      C Offline
                      code_fodder
                      wrote on last edited by
                      #10

                      hmmm....well if windows never gives the close signal/event to a hidden window/app then there is not much Qt can do about that :o

                      To test when events you do get, you can implement
                      @
                      bool QObject::event(QEvent * e) [virtual]
                      @

                      In your MainWindow, and just print out ALL event types, somthing like (not tested code):

                      @
                      bool MainWindow::event(QEvent * e)
                      {
                      qDebug() << "Event type:" << e->type();

                      // I think this means the event has now been "consumed" and no further processing is required. So false means, carry on...
                      return false;
                      

                      }
                      @

                      Then you can check if there is ANY event that comes when you shutdown windows

                      1 Reply Last reply
                      0
                      • P Offline
                        P Offline
                        pjeroo
                        wrote on last edited by
                        #11

                        code_fodder, it is not good, because there are only two events when i'm trying to shutdown Windows.. and these events are also using in application initialization. QEvent::ActivationChange, QEvent::WindowActivate . now i'm trying to catch windows messages with winapi function PeekMessage

                        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