title: SIGNAL and SLOT between 2 windows QT
body: <p>Salam Wa Alikom</p>
  
  <p>Hi Everyone :)</p>
  
  <p>i want to connect to windows using SIGNAL and SLOT so i can pass variable from the first window to the second windows</p>
  
  <p>exactly i want to pass the value of <code>nom</code> from the lineEDIT from login.cpp to menu.cpp</p>
  
  <p>i have 2 windows </p>
  
  <blockquote>
    <p>login.ui
    and
    menu.ui</p>
  </blockquote>
  
  <p>this is login.h</p>
  
  <pre><code>#ifndef LOGIN_H
  #define LOGIN_H
  
  #include &lt;QMainWindow&gt;
  #include &lt;QtSQl&gt;
  #include &lt;QSqlQuery&gt;
  #include &lt;QSqlError&gt;
  #include &lt;QDebug&gt;
  #include &lt;QFileInfo&gt;
  #include &lt;QDialog&gt;
  #include "menu.h"
  
  namespace Ui {
  class login;
  }
  
  class login : public QMainWindow
  {
      Q_OBJECT
  
  public:
      explicit login(QWidget *parent = 0);
      ~login();
  
  private slots:
      void on_pushButton_clicked();
  
  
  private:
      Ui::login *ui;
      Menu *menu;
      QSqlDatabase db;
  };
  
  #endif // LOGIN_H
  </code></pre>
  
  <p>login.cpp</p>
  
  <pre><code>#include "login.h"
  #include "ui_login.h"
  #include "QPixmap"
  #include "QCryptographicHash"
  #include &lt;QDialog&gt;
  
  
  login::login(QWidget *parent) :
      QMainWindow(parent),
      ui(new Ui::login)
  {
      ui-&gt;setupUi(this);
      connect(ui-&gt;horizontalSlider,SIGNAL(valueChanged(int)),
              ui-&gt;spinBox,SLOT(setValue(int)));
  
      // logos header
      QPixmap isem_img("C:/Users/Amine/Documents/QT/E-LogBook/resource/img/ISEM.png");
      ui-&gt;img_ISEM-&gt;setPixmap(isem_img);
      QPixmap mm_img("C:/Users/Amine/Documents/QT/E-LogBook/resource/img/MM.png");
      ui-&gt;img_MM-&gt;setPixmap(mm_img);
  
      // Connexion database
      db = QSqlDatabase::addDatabase("QMYSQL");
      db.setHostName("localhost");
      db.setUserName("root");
      db.setPassword("");
      db.setDatabaseName("journal_machine");
  
      // ouverture database
      if(db.open())
      {
          ui-&gt;label_db_status-&gt;setText("Connecté");
      }else{
          ui-&gt;label_db_status-&gt;setText("Connexion echoué");
      }
  }
  
  login::~login()
  {
      delete ui;
  }
  
  void login::on_pushButton_clicked()
  { menu = new Menu(this);
      menu -&gt;show();
      QString password,nom,password_db;
      nom = ui-&gt;lineEdit_nom-&gt;text();// get data from input
      password = ui-&gt;lineEdit_password-&gt;text();// get data from input
  
      if (password == NULL || nom == NULL){ // si les cases sont vides
          ui-&gt;label_etat-&gt;setText("Champ non rempli");
      } else
      {
          QSqlQuery query;
          query.exec("SELECT * FROM `equipage` WHERE Nom='"+nom+"'");// Query
          if (query.next() == true) {
          password_db = query.value(2).toString(); // get value from mysql
          QString password_md5 = QString(QCryptographicHash::hash((password.toUtf8()),QCryptographicHash::Md5).toHex());// cryptage du password
          if (password_md5 == password_db) {// si le mot de pass est correct
  
  
          //  this-&gt;hide();
          } else {
              // si le mot de pass est faux
          }
          }
          query.finish();
      }
  }
  </code></pre>
  
  <p>and menu.h</p>
  
  <pre><code>#ifndef MENU_H
  #define MENU_H
  
  #include &lt;QMainWindow&gt;
  
  namespace Ui {
  class Menu;
  }
  
  class Menu : public QMainWindow
  {
      Q_OBJECT
  
  public:
      explicit Menu(QWidget *parent = 0);
      ~Menu();
  
  private slots:
      void on_pushButton_2_clicked();
  
  private:
      Ui::Menu *ui;
  };
  
  #endif // MENU_H
  </code></pre>
  
  <p>menu.cpp</p>
  
  <pre><code>#include "menu.h"
  #include "ui_menu.h"
  #include "login.h"
  
  Menu::Menu(QWidget *parent) :
      QMainWindow(parent),
      ui(new Ui::Menu)
  {
      ui-&gt;setupUi(this);
  
  
  }
  Menu::~Menu()
  {
      delete ui;
  }
  </code></pre>
  
  <p>finaly main.cpp</p>
  
  <pre><code>#include "login.h"
  #include "menu.h"
  #include &lt;QApplication&gt;
  
  int main(int argc, char *argv[])
  {
      QApplication a(argc, argv);
      login w;
      Menu z;
      w.show();
      z.show();
      return a.exec();
  }
  </code></pre>
  
  <p>Thanks in advance
  Chokran :)</p>