在Qt design下,先设计下界面
分别把伙伴关系、信号/槽关系、响应函数设计出来:
接下来编写代码:
//dialog.h
#ifndef DIALOG_H
#define DIALOG_H
#include <QtWidgets/QMainWindow>
#include "ui_dialog.h"
#include <QMessageBox>
class Dialog : public QMainWindow
{
Q_OBJECT
private slots:
void enableLoginButton( const QString &);
void login();
public:
Dialog(QWidget *parent = 0);
~Dialog();
private:
Ui::DialogClass ui;
};
#endif // DIALOG_H
//dialog.cpp
#include "dialog.h"
Dialog::Dialog(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
}
Dialog::~Dialog()
{
}
void Dialog::enableLoginButton(const QString & text)
{
ui.loginButton->setEnabled(!text.isEmpty());
}
void Dialog::login()
{
QString userName = ui.userNamerLEdit->