自定义login 控件
Login头文件
#ifndef LOGIN_H
#define LOGIN_H
#include <QWidget>
namespace Ui {
class Login;
}
class Login : public QWidget
{
Q_OBJECT
public:
explicit Login(QWidget *parent = 0);
~Login();
signals:
void login(QString ,QString );
private slots:
void on_pushButton_clicked();
private:
Ui::Login *ui;
};
#endif // LOGIN_H
Login 源文件
#include "login.h"
#include "ui_login.h"
Login::Login(QWidget *parent) :
QWidget(parent),
ui(new Ui::Login)
{
ui->setupUi(this);
}
Login::~Login()
{
delete ui;
}
void Login::on_pushButton_clicked()
{
QString name=ui->UserName->toPlainText();
QString pwd=ui->UserPwd->toPlainText();
login(name,pwd);
}
主窗口
头文件
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
public slots:
void handleLogin(QString name,QString pwd);
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
源文件
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "login.h"
#include <QDebug>
#include <QMessageBox>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
Login *lg=new Login();
lg->setParent(this);
QSize size;
size.setWidth(200);
size.setHeight(200);
lg->setBaseSize(size);
connect(lg,SIGNAL(login(QString ,QString )),this,SLOT(handleLogin(QString , QString)));
}
void MainWindow::handleLogin(QString name,QString pwd)
{
qDebug()<<name<<pwd;
// QMessageBox.information()
QMessageBox::critical(NULL, name, pwd, QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
}
MainWindow::~MainWindow()
{
delete ui;
}