Q:

How to pass a variable from one qt form to other form qt form?

Hello i have a problem related to passing an entered string from one form to the other form.The header file of this code has getters and setters while a private variable Username is also present.I want to pass an entered string username from this code
void norm_user::on_pushButton_clicked(){
login conn;
QString  Password,username;
username = ui->lineEdit_username->text();
set_username(username);

Password = ui->lineEdit_password->text();

if(!conn.connOpen2())
{
    qDebug() << "No connection to db";
    return;
}

conn.connOpen2();
QSqlQuery qry;

qry.prepare("SELECT Username, Password FROM Users WHERE Username=\'" +username+ "\' AND Password=\'" +Password+ "\'");

if(qry.exec())
{
    if(qry.next())
    {
        ui->label_check_1->setText("[+] Valid username and password");
        QString msg = "Username = " + qry.value(0).toString() + " \n" +
                "Password = " + qry.value(1).toString() + " \n" +
                "Role = " + qry.value(2).toString();

        QMessageBox::warning(this,"Login was successful",msg);

        ui->testing->setText(get_username());

       users_platform platform;
        platform.setModal(true);
        platform.exec();

    }
    else
    {
        ui->label_check_1->setText("[-]Wrong username or password");
    }
}

}
This is the second form of the project where iam suppose to pass the string in the qt label.How am i suppose to pass the string to this code ?
users_platform::users_platform(QWidget *parent ) :
QDialog(parent),
ui(new Ui::users_platform)
{
norm_user c;
ui->setupUi(this);
login conn;
QString usr;
QFileInfo checkfile(path_2);

if(checkfile.isFile())
{
     if(conn.connOpen2())
     {
         ui->label_check->setText("[+]Connected to Database");
         ui->test_1->setText(c.get_username());
     }
     else
     {
         ui->label_check->setText("[!] Database not found");
     }
 }

}

A:

First of all, you have an unnecessary circular dependency in your code. You are instantiating an users_platform inside your norm_user and also you are creating a norm_user inside your users_platform's constructor. I see no reason for this, because your norm_user c variable will not hold any usable information.
If norm_user is the creator of the users_platform platform, it should be eligible to pass any necessary information. You could simply pass it by the constructor users_platform::users_platform(QWidget *parent, const QString& username). Or you could pass by a setter. Some will argue, that this is not a good practice, but it will do the job. Unfortunately, you do a lot of things in the constructor of your norm_user, so this wont really work for you. Also, you could use signals and slots for passing variables, but with your current design this wont really help you either.

