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] signal 'destroyed' is not emited
Forum Updated to NodeBB v4.3 + New Features

[solved] signal 'destroyed' is not emited

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

    Hi,

    I wonder why signal 'destroyed' is not emited in this case:

    @
    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);

    MainController mainController;
    mainController.init();
    emit mainController.signal_start();
    
    return  a.exec();    
    

    }
    @

    where

    @
    class MainController : public QObject {

    Q_OBJECT
    
    private:
        QThread mTerminalInputThread;
        TerminalInput* mTerminalInput;
    
    public:
        void init();
    
    signals:
        void signal_start();
    
    public slots:
        void slot_quit();
        void slot_destroyed();
    

    };
    // --- sources ---
    void MainController::init(){
    mTerminalInput = new TerminalInput();
    mTerminalInput->moveToThread(&mTerminalInputThread);
    QObject::connect(mTerminalInput, SIGNAL(destroyed()), this, SLOT(slot_destroyed()));
    QObject::connect(this, SIGNAL(signal_start()), mTerminalInput, SLOT(slot_loop()));
    QObject::connect(mTerminalInput, SIGNAL(signal_quit()), this, SLOT(slot_quit()));
    mTerminalInputThread.start();
    }

    void MainController::slot_quit(){
    mTerminalInput->deleteLater();
    mTerminalInputThread.quit();
    mTerminalInputThread.wait();
    QApplication::quit();
    }

    void MainController::slot_destroyed(){
    fprintf(stdout, "mTerminalInput destroyed !!!\n");
    }
    @

    and

    @
    class TerminalInput : public QObject {
    Q_OBJECT

    public:
        ~TerminalInput();
    
    signals:
        void signal_quit();
    
    public slots:
        void slot_loop();
    

    };
    // --- sources ---
    TerminalInput::~TerminalInput(){
    fprintf(stdout, "~TerminalInput");
    }

    void TerminalInput::slot_loop(){
    emit signal_quit();
    }
    @

    The destructor of mTerminalInput is called, but I do not receive a signal 'destroyed'. What am I doing wrong here?

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tilsitt
      wrote on last edited by
      #2

      Hi,

      I am not sure, but when you call QApplication::quit(), I think the apllication stops the event loop so you signal will not be resolved. QApplication::quit() is equivalent to call exit(0): it is a "brutal" end. Depending on the design of your application, you should look at something like "QApplication::closeAllWindows()":http://qt-project.org/doc/qt-5/qapplication.html#closeAllWindows instead.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        minbraz
        wrote on last edited by
        #3

        Hi, tilsitt,

        thanks for response. Yes, QApplication::closeAllWindows()
        solved the problem in my main program, which do have windows.

        The 'destroyed' signal is also emited in bug reconstruction code (I have posted) when using QApplication::closeAllWindows() instead of QApplication::quit(). But this time a desctructor is not called and program stops responding. I guess, it is because there is any windows.

        1 Reply Last reply
        0
        • T Offline
          T Offline
          tilsitt
          wrote on last edited by
          #4

          Once again it's all depending on the design of your project. I mentioned QApplication::closeAllWindows() because you are using a QApplication object in your example, so I guessed you were using windows. Another way could have been to call QApplication::quit() in MainController::slot_destroyed() but without knowing your architecture and your goals, I can't figure out if that really is what you want.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            minbraz
            wrote on last edited by
            #5

            QApplication::closeAllWindows() works in fixed bug reconstruction code.

            @int main(int argc, char *argv[])
            {
            QApplication a(argc, argv);

            QDialog dialog;  // <<--
            dialog.show();   // <<--
            
            MainController mainController;
            mainController.init();
            emit mainController.signal_start();
            
            return  a.exec&#40;&#41;;    
            

            }@

            The problem is solved.

            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