|
初学者吧.....你把判断语句写在构造函数中怎么有作用..... - /********************************************************************************
- ** Form generated from reading UI file 'login.ui'
- **
- ** Created: Mon Jul 12 21:36:32 2010
- ** by: Qt User Interface Compiler version 4.7.0
- **
- ** WARNING! All changes made in this file will be lost when recompiling UI file!
- ********************************************************************************/
- #ifndef UI_LOGIN_H
- #define UI_LOGIN_H
- #include <QtCore/QVariant>
- #include <QtGui/QAction>
- #include <QtGui/QApplication>
- #include <QtGui/QButtonGroup>
- #include <QtGui/QDialog>
- #include <QtGui/QDialogButtonBox>
- #include <QtGui/QHeaderView>
- #include <QtGui/QLabel>
- #include <QtGui/QLineEdit>
- QT_BEGIN_NAMESPACE
- class Ui_Login
- {
- public:
- QDialogButtonBox *buttonBox;
- QLineEdit *UserName;
- QLineEdit *PWD;
- QLabel *label;
- QLabel *label_2;
- void setupUi(QDialog *Login)
- {
- if (Login->objectName().isEmpty())
- Login->setObjectName(QString::fromUtf8("Login"));
- Login->resize(400, 300);
- buttonBox = new QDialogButtonBox(Login);
- buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
- buttonBox->setGeometry(QRect(30, 240, 341, 32));
- buttonBox->setOrientation(Qt::Horizontal);
- buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
- UserName = new QLineEdit(Login);
- UserName->setObjectName(QString::fromUtf8("UserName"));
- UserName->setGeometry(QRect(160, 90, 113, 20));
- PWD = new QLineEdit(Login);
- PWD->setObjectName(QString::fromUtf8("PWD"));
- PWD->setGeometry(QRect(160, 140, 113, 20));
- label = new QLabel(Login);
- label->setObjectName(QString::fromUtf8("label"));
- label->setGeometry(QRect(70, 90, 54, 12));
- label_2 = new QLabel(Login);
- label_2->setObjectName(QString::fromUtf8("label_2"));
- label_2->setGeometry(QRect(70, 150, 54, 12));
- retranslateUi(Login);
- QObject::connect(buttonBox, SIGNAL(accepted()), Login, SLOT(TOOTAccpted()) );
- QObject::connect(buttonBox, SIGNAL(rejected()), Login, SLOT(reject()));
- QMetaObject::connectSlotsByName(Login);
- } // setupUi
- void retranslateUi(QDialog *Login)
- {
- Login->setWindowTitle(QApplication::translate("Login", "Dialog", 0, QApplication::UnicodeUTF8));
- label->setText(QApplication::translate("Login", "\347\224\250\346\210\267\345\220\215", 0, QApplication::UnicodeUTF8));
- label_2->setText(QApplication::translate("Login", "\345\257\206\347\240\201", 0, QApplication::UnicodeUTF8));
- } // retranslateUi
- };
- namespace Ui {
- class Login: public Ui_Login {};
- } // namespace Ui
- QT_END_NAMESPACE
- #endif // UI_LOGIN_H
- /**************************************************************************
- ** Copyright @ 2010 TOOTzoe.com
- ** Special keywords: Administrator 2010-7-12 2010
- ** Environment variables: %$VARIABLE%
- ** To protect a percent sign, use '%'.
- **
- **
- ** E-mail : toot@tootzeo.com
- ** Tel : 13712943464
- ** Website: http://www.tootzoe.com
- **
- **************************************************************************/
- //------------------------------------------------------------------------
- #ifndef LOGIN_H
- #define LOGIN_H
- #include <QDialog>
- namespace Ui {
- class Login;
- }
- class Login : public QDialog
- {
- Q_OBJECT
- public:
- explicit Login(QWidget *parent = 0);
- ~Login();
- public slots:
- void TOOTAccpted();
- protected:
- void changeEvent(QEvent *e);
- private:
- Ui::Login *ui;
- };
- #endif // LOGIN_H
- /**************************************************************************
- ** Copyright @ 2010 TOOTzoe.com
- ** Special keywords: Administrator 2010-7-12 2010
- ** Environment variables: %$VARIABLE%
- ** To protect a percent sign, use '%'.
- **
- **
- ** E-mail : toot@tootzeo.com
- ** Tel : 13712943464
- ** Website: http://www.tootzoe.com
- **
- **************************************************************************/
- //------------------------------------------------------------------------
- #include <QMessageBox>
- #include "login.h"
- #include "ui_login.h"
- Login::Login(QWidget *parent) :
- QDialog(parent),
- ui(new Ui::Login)
- {
- ui->setupUi(this);
- }
- Login::~Login()
- {
- delete ui;
- }
- void Login::changeEvent(QEvent *e)
- {
- QDialog::changeEvent(e);
- switch (e->type()) {
- case QEvent::LanguageChange:
- ui->retranslateUi(this);
- break;
- default:
- break;
- }
- }
- void Login::TOOTAccpted()
- {
- if(ui->UserName->text() == "toot" && ui->PWD->text() == "cn")
- accept();
- else
- QMessageBox::warning(this,tr("输入法错误...."),tr("请重新输入....."));
- }
- #include <QApplication>
- #include <QTextCodec>
- #include "mainfrm.h"
- #include "login.h"
- int main(int argc, char *argv[])
- {
- QApplication app(argc, argv);
- QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
- QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
- mainfrm _mainfrm;
- Login login;
- if(login.exec()==QDialog::Accepted )
- _mainfrm.show();
- else return 1;
- return app.exec();
- }
|