QT is used in the new project. Therefore, we have recently studied QT and installed and deployed QT creator yesterday. Now we will start the first program immediately.
Make a simple login interface function
As follows:
Code Section
View code
# Include <qtgui/qapplication> # include "mainwindow. H "# include" logindlg. H "int main (INT argc, char * argv []) {qapplication A (argc, argv); mainwindow W; // logindlg login on the main interface; // if(login.exe C () on the logon Interface () = qdialog: accepted) {W. show (); Return a.exe C ();} else return 0 ;}View code
#ifndef LOGINDLG_H#define LOGINDLG_H#include <QDialog>namespace Ui { class LoginDlg;}class LoginDlg : public QDialog { Q_OBJECTpublic: LoginDlg(QWidget *parent = 0); ~LoginDlg();protected: void changeEvent(QEvent *e);private: Ui::LoginDlg *ui;private slots: void on_pushButton_2_clicked(); void on_pushButton_clicked();};#endif // LOGINDLG_H
View code
# Include "logindlg. H "# include" ui_logindlg.h "# include" qmessagebox. H "# include" qtextcodec. H "logindlg: logindlg (qwidget * parent): qdialog (parent), UI (new UI: logindlg) {UI-> setupui (this);} logindlg ::~ Logindlg () {Delete UI;} void logindlg: changeevent (qevent * E) {qdialog: changeevent (E); Switch (e-> type () {Case qevent:: languagechange: UI-> retranslateui (this); break; default: break;} void logindlg: on_pushbutton_clicked () {If (this-> UI-> txtname-> text (). trimmed () = tr ("admin") & this-> UI-> txtpwd-> text (). trimmed () = tr ("admin") {accept ();} else {qtextcodec: setcodecfortr (qtextcodec: codecforn Ame ("GBK"); qmessagebox: Warning (this, TR ("warning"), TR ("Incorrect username or password! "), Qmessagebox: Yes); this-> UI-> txtname-> clear (); this-> UI-> txtpwd-> clear (); this-> UI-> txtname-> setfocus () ;}} void logindlg: on_pushbutton_2_clicked () {This-> close ();}
The code is simple to implement basic functions