C++備忘-QT(4),備忘-qt

來源:互聯網
上載者:User

C++備忘-QT(4),備忘-qt

使用者登入-creator編程

畫好以下介面:

 

編譯時間,會自動產生如下內容的標頭檔ui_mainwindow.h

 

 

/********************************************************************************

** Form generated from reading UI file'mainwindow.ui'

**

** Created by: Qt User Interface Compilerversion 5.4.0

**

** WARNING! All changes made in this filewill be lost when recompiling UI file!

********************************************************************************/

 

#ifndef UI_MAINWINDOW_H

#define UI_MAINWINDOW_H

 

#include <QtCore/QVariant>

#include <QtWidgets/QAction>

#include <QtWidgets/QApplication>

#include <QtWidgets/QButtonGroup>

#include <QtWidgets/QHBoxLayout>

#include <QtWidgets/QHeaderView>

#include <QtWidgets/QLabel>

#include <QtWidgets/QLineEdit>

#include <QtWidgets/QMainWindow>

#include <QtWidgets/QMenuBar>

#include <QtWidgets/QPushButton>

#include <QtWidgets/QStatusBar>

#include <QtWidgets/QToolBar>

#include <QtWidgets/QVBoxLayout>

#include <QtWidgets/QWidget>

 

QT_BEGIN_NAMESPACE

 

class Ui_MainWindow

{

public:

   QWidget *centralWidget;

   QVBoxLayout *verticalLayout;

   QHBoxLayout *horizontalLayout_2;

   QLabel *userLb;

   QLineEdit *userNameLe;

   QHBoxLayout *horizontalLayout_3;

  ...


 

編寫cpp檔案

mainwindow.cpp

#include"mainwindow.h"

#include"ui_mainwindow.h"

#include<QMessageBox>

 

MainWindow::MainWindow(QWidget*parent) :

    QMainWindow(parent),

    ui(new Ui::MainWindow)

{

    ui->setupUi(this);

}

 

MainWindow::~MainWindow()

{

    delete ui;

}

 

 

voidMainWindow::on_okBt_clicked()

{

    if(ui->userNameLe->text().compare("user")==0 &&ui->passWordLe->text().compare("123")==0)

    {

        QMessageBox::information(this, "登入系統","密碼正確",

                                    QMessageBox::Ok);

        close();

    }

    else

    {

        QMessageBox::information(this, "登入系統","密碼錯誤,請重新輸入!",

                                    QMessageBox::Ok);

    }

}

 

void MainWindow::on_quitBt_clicked()

{

     if (QMessageBox::information(this, "登入系統", "退出系統否?",

                                QMessageBox::Yes,QMessageBox::No)==QMessageBox::Yes){

         close();

 

     }

 

}

 


本部落格所有內容是原創,如果轉載請註明來源http://blog.csdn.net/myhaspl/

setupUi將自動產生一些connect關係,其中有以下語句

QMetaObject::connectSlotsByName(MainWindow);

將按訊號名稱自動產生槽

比如

connect(quitBt,SIGNAL(clicked()),this,SLOT(on_quitBt_clicked));

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.