VS+Qt+C++ bank queuing calling system

 Featured program examples

VS+Qt+C++ bank queuing calling system

If you need to install the operating environment or remote debugging, see the personal QQ business card at the bottom of the article, and professional and technical personnel will assist remotely!

foreword

This blog writes code for <<VS+Qt+C++ Bank Queue Calling System>>, with user login, administrator login, addition, deletion, modification and query, the code is neat, regular, and easy to read. The first choice for learning and application recommendation.


Article directory

1. Required tool software

2. Use steps

        1. Import library

        2. Code implementation

       3. Running results

3. Online assistance

1. Required tool software

1. VS, Qt

2. C++

2. Use steps

1. Import library

#pragma once

#include <QtWidgets/QMainWindow>
#include "ui_AdminManager.h"


#include <QWidget>

#include <QtSql/QSqlDatabase>
#include <QtSql/QSqlError>
#include <QtSql/QtSql>

2. Code implementation

code show as below:

#if defined(_MSC_VER) && (_MSC_VER >= 1600)
#pragma execution_character_set("utf-8")
#endif

#include "UserManager.h"


#include<iostream>
using namespace std;

UserManager::UserManager(QWidget *parent)
	: QMainWindow(parent)
{
	ui.setupUi(this);


    QObject::connect(ui.pushButton_4, SIGNAL(clicked()), this, SLOT(on_findButton_clicked()));
    QObject::connect(ui.pushButton, SIGNAL(clicked()), this, SLOT(on_addButton_clicked()));
    ui.pushButton_4->setVisible(true);

    //ui.tableWidget->setAlternatingRowColors(true); // 隔行变色
    //ui.tableWidget->setPalette(QPalette(QColor(220, 250, 255)));//参数还可写成QPalette(Qt::blue)
    
    //背景色
    ui.tableWidget->setStyleSheet("QTableView::Item{background-color:green}");



    db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName("information.db");
    // 2. 打开数据库
    if (!db.open())
        qDebug() << "open error" << db.lastError();

    QSqlQuery query;
    //判断information是否已存在,存在则不创建,不存在这创建
    QString sqlFindTableName = QString("select count(*) from informationTable where type = 'table' and name='%1'").arg("informationTable");  //功能同上

    if (!query.exec(sqlFindTableName))
        qDebug() << "findTable error" << db.lastError();
    bool isTableExist = query.exec(sqlFindTableName);
    qDebug() << isTableExist;
    if (!isTableExist)
    {
        //表  字段有id name class
        QString sqlCreate = QString("create table informationTable(id integer primary key autoincrement,"
            "name varchar(20),"
            "gender varchar(20),"
            "age varchar(20),"
            "class int);");
        if (!query.exec(sqlCreate))
            qDebug() << "create table error" << db.lastError();
    }

}

//显示所有
void UserManager::on_findButton_clicked()
{
    std::cout << "test_ " << std::endl;

    if (true == db.open())
    {
        QSqlQuery query(db);
        if (query.exec("select * from informationTable"))
        {
            ui.tableWidget->clearContents();
            ui.tableWidget->setRowCount(0);

            while (query.next())
            {
                int rowCount = ui.tableWidget->rowCount();
                ui.tableWidget->insertRow(rowCount);

                QTableWidgetItem* columnItem0 = new QTableWidgetItem(
                    query.value(0).toString());
                QTableWidgetItem* columnItem1 = new QTableWidgetItem(
                    query.value(1).toString());
                QTableWidgetItem* columnItem2 = new QTableWidgetItem(
                    query.value(2).toString());
                QTableWidgetItem* columnItem3= new QTableWidgetItem(
                    query.value(3).toString());
                QTableWidgetItem* columnItem4 = new QTableWidgetItem(
                    query.value(4).toString());

                ui.tableWidget->setItem(rowCount, 0, columnItem0);
                ui.tableWidget->setItem(rowCount, 1, columnItem1);
                ui.tableWidget->setItem(rowCount, 2, columnItem2);
                ui.tableWidget->setItem(rowCount, 3, columnItem3);
                ui.tableWidget->setItem(rowCount, 4, columnItem4);

            }
        }
    }

}


//添加
void UserManager::on_addButton_clicked()
{
    QString IDEd = ui.idLineEdit->text();
    if (IDEd != "")
    {
        QString status = ui.comboBox->currentText();;
        //将通过数据库接口的访问,将数据插入到数据库中
        QSqlQuery query;
        //QString sqlInert = QString("insert into informationTable(name, class)" "values('%1', %2)").arg(nameEd).arg(classNum);
        QString sqlInert = QString("insert into informationTable(ID, name)" "values('%1','%2')").arg(IDEd, status);
        if (!query.exec(sqlInert))
            qDebug() << "insert data error" << db.lastError();
        on_findButton_clicked();
    }
}



3. Running results

 

 

 

3. Online assistance:

If you need to install the operating environment or remote debugging, see the personal QQ business card at the bottom of the article, and professional and technical personnel will assist remotely!
1) Remote installation and operation environment, code debugging
2) Qt, C++, Python entry guide
3) Interface beautification
4) Software production

Blogger recommended article: python face recognition statistics qt form - CSDN Blog

Blogger recommended article: Python Yolov5 flame smoke recognition source code sharing - CSDN blog

                         Python OpenCV recognizes the number of people entering and exiting the pedestrian entrance - python recognizes the number of people - CSDN Blog

Personal blog homepage: alicema1111's blog_CSDN blog-Python, C++, bloggers in the field of web pages

Click here for all the blogger's articles: alicema1111's blog_CSDN blog-Python, C++, bloggers in the field of web pages

Guess you like

Origin blog.csdn.net/alicema1111/article/details/130446909