我有一个登录页面(main_window),我想在成功登录后在form_2
中创建的标签中设置用户名。如何从main_window
中的form_2
访问用户名(line_edit)
我试过创建一个从main_window类调用的函数
我正在使用Qt 5.9。
void login_card1::on_pushButton_clicked(){
QString us;
QSqlQuery q;
portal k;
q.prepare("select * from login where username = ? and password = ?");
q.addBindValue(ui->lineEdit->text());
q.addBindValue(ui->lineEdit_2->text());
if(q.exec())
{
if(q.next())
{
us = ui->lineEdit->text();
k.labeltext(us);
ui->output->append("Welcome, opening portal...");
portal p;
p.setModal(this);
p.exec();
}
else if(ui->lineEdit->text().isEmpty())
{
ui->output->append("please enter your username and password\nif you are a hacker please wait in the OFFICE ROOM...");
}
else
{
ui->output->append("incorrect username or password, please try again...");
}
}}
form_2.cpp
中textlabel函数的代码void portal::labeltext(QString u){
ui->label_2->setText(u);
}