title: Qt emit signal from a class to class
body: <p>I've tried to emit a custom signal login() from my loginmanager class to the mainwindow. The signal is fired on the loginButtonClicked slot, and to my understand on the signal/slot mechanism, it should be able to capture any signal fired event and "look" for the corresponding slot to be execute. But it doesn't work as what I've think.</p>
  
  <p>The connect function returns 1, which means it is able to be implemented in the moc file, and it DOES work if i run the m_LoginManager->setLogin() which fires the login() signal. </p>
  
  <p>But what I prefer is the signal is emitted by the loginButton, and pass to the mainwindow to be process (in this case, init()).</p>
  
  <p>Please correct me if I'm wrong.</p>
  
  <p>Below are the code.</p>
  
  <p>loginmanager.cpp</p>
  
  <pre><code>LoginManager::LoginManager(QWidget * parent) : QWidget(parent) 
  {
      ui.setupUi(this);
  
      connect(ui.loginButton, SIGNAL(clicked()), this, SLOT(loginButtonClicked());
  }
  
  LoginManager::~LoginManager() 
  {
  
  }
  
  void LoginManager::setLogin()
  {
      emit login();
  }
  
  void LoginManager::loginButtonClicked()
  {
      setLogin();
  }
  </code></pre>
  
  <p>loginmanager.hpp</p>
  
  <pre><code>#include &lt;QWidget&gt;
  #include "ui_loginmanager.h"
  
  class DatabaseManager;
  class SettingManager;
  
  class LoginManager : public QWidget 
  {
      Q_OBJECT
  
  public:
      LoginManager(QWidget * parent = Q_NULLPTR);
      ~LoginManager();
  
      void setLogin();
  
  signals:
      void login();
  
  public slots:
      void loginButtonClicked();
  
  private:
      Ui::LoginManager ui;
  };
  </code></pre>
  
  <p>mainwindow.hpp</p>
  
  <pre><code>#include &lt;QtWidgets/QMainWindow&gt;
  #include "ui_safeboxmanager.h"
  
  class SafeboxManager : public QMainWindow
  {
      Q_OBJECT
  
  public:
      SafeboxManager(QWidget *parent = 0);
      ~SafeboxManager();
  
  public slots:
      void init();
  
  private:
      Ui::SafeboxManagerClass ui;
      LoginManager*       m_LoginManager;
  };
  
  #endif // SAFEBOXMANAGER_H
  </code></pre>
  
  <p>mainwindow.cpp</p>
  
  <pre><code>#include "safeboxmanager.hpp"
  #include "loginmanager.hpp"
  
  SafeboxManager::SafeboxManager(QWidget *parent)
      : QMainWindow(parent)
  {
      ui.setupUi(this);
  
      m_LoginManager = new LoginManager();
  
      ui.mainToolBar-&gt;setEnabled(false);
      ui.tableWidget-&gt;setEnabled(false);
  
      connect(m_LoginManager, SIGNAL(login()), this, SLOT(init()));
  
      //m_LoginManager-&gt;setLogin() &lt;&lt; this work
  }
  
  SafeboxManager::~SafeboxManager()
  {
  
  }
  
  void SafeboxManager::init()
  {
      ui.mainToolBar-&gt;setEnabled(true);
      ui.tableWidget-&gt;setEnabled(true);
  }
  </code></pre>