title: Is it normal not to be able to reuse a variable obtained from a connect()?
body: <p>I made a login page and I'm trying to retrieve the name of the user who logged in and then display it in the next page and to adjust my program according to the person logged in.</p>
  
  <p>But I desperately run into the same problem, I can't extract the variable from the slot to reuse it and do everything I have to do with it :(
  So I wonder if it's a specificity of the slot (I start Qt and I don't know much about it) or if I'm the one who doesn't do things correctly. </p>
  
  <p>PS: I've obviously read and reread the Qt documentation about this but it doesn't help too much.</p>
  
  <p>My code:</p>
  
  <p>glybook.cpp (where I want to put the login information)</p>
  
  <pre><code>#include "ui_glybook.h"
  
  glybook::glybook(QWidget *parent) :
      QMainWindow(parent),
      ui(new Ui::glybook)
  {
      ui-&gt;setupUi(this);
      //qDebug() &lt;&lt; receiveConnectionData(username);
      test();
  }
  
  void glybook::receiveConnectionData(QString name){
      username = name;
      //qDebug() &lt;&lt; username;
      ui-&gt;label-&gt;setText("Connected: "+username);
  }
  
  void glybook::test(){
  
      qDebug() &lt;&lt; ui-&gt;label-&gt;text();
  }
  
  glybook::~glybook()
  {
      delete ui;
  }
  
  </code></pre>
  
  <p>glybook.h</p>
  
  <pre><code>class Glybook;
  }
  
  class Glybook : public QMainWindow
  {
      Q_OBJECT
  
  public:
      explicit Glybook(QWidget *parent = nullptr);
      ~Glybook();
  
      void test();
  
  private slots:
      void receiveConnectionData(QString);
  
  private:
      Ui::Glybook *ui;
  
      QString username;
  };
  </code></pre>
  
  <p>connection.cpp (login page)</p>
  
  <pre><code>#include "./ui_connection.h"
  
  Connection::Connection(QWidget *parent)
      : QMainWindow(parent)
      , ui(new Ui::Connection)
  {
      ui-&gt;setupUi(this);
  }
  
  Connection::~Connection()
  {
  delete ui;
  }
  
  void Connection::on_pushButton_clicked()
  {
  
  QString user =  ui-&gt;lineEdit-&gt;text();
  QString pass = ui-&gt;lineEdit_2-&gt;text();
  
  glybook* page = new glybook();
  
  connect(this, SIGNAL(sendConnectData(QString)), page, SLOT(receiveConnectionData(QString)));
  
  emit sendConnectData(user);
  page-&gt;show();
  this-&gt;close();
  }
  
  
  </code></pre>
  
  <p>connection.h</p>
  
  <pre><code>#define CONNECTION_H
  
  #include &lt;QMainWindow&gt;
  #include &lt;QMessageBox&gt;
  #include "glybook.h"
  
  QT_BEGIN_NAMESPACE
  namespace Ui { class Connection; }
  QT_END_NAMESPACE
  
  class Connection : public QMainWindow
  {
      Q_OBJECT
  
  public:
      Connection(QWidget *parent = nullptr);
      ~Connection();
  
  private slots:
      void on_pushButton_clicked();
  
  signals:
      void sendConnectData(QString);
  
  private:
      Ui::Connection *ui;
  };
  #endif // CONNECTION_H
  
  </code></pre>
  
  <p>main.cpp</p>
  
  <pre><code>
  #include &lt;QApplication&gt;
  
  int main(int argc, char *argv[])
  {
      QApplication a(argc, argv);
      Connection w;
      w.show();
      return a.exec();
  }
  </code></pre>