Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize General Database request in Qt Database

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you how to achieve general database requests in the Qt database, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

I. Preface

The database request is based on the collection of the database, and the data is obtained in the form of http request, so it is separated from the database component, and the general http request is used to get the database from the database, which is very versatile. For example, the data collected by the other party with java is stored in the database, and the data collected by c # is stored in the other area. Then the unified rules and specifications stipulate a request mechanism, timer or thread to take the execution request, get the json data, take out the results one by one, and send signals in the way of array collection.

The visual large screen electronic Kanban program written before also uses the way that http requests the database to collect and display the data, which requires multi-party cooperation. As for who put the data in the database, it has nothing to do with the large screen program itself, and the corresponding can be either the data stored in the requested form or directly written in the database, that is, it can be java or c #. Large screen UI display just take out the data and display it according to the rules, and you can be as beautiful as you want. Qss and painter are in hand, there are coordinates in the heart, and everything is painter.

II. Functional features

At the same time, it supports a variety of databases such as odbc, sqlite, mysql, postgresql, sqlserver, oracle, people's Congress and so on.

A database class can not only manage local database communication, but also support remote database communication.

Database threads support the execution of various sql statements, including individual and batch statements.

All classes in the component print messages, error messages, and execution results are signaled.

Integrated database general page turning class (responsible for specific processing logic), with paging navigation controls (responsible for appearance), to form a super powerful page turning control.

Integrated database automatic cleaning class, set the maximum number of records to automatically clean up early data in the background.

Integrated custom delegate class, supporting check boxes, text boxes, drop-down boxes, date boxes, fine-tuning boxes, progress bars, and so on.

At the same time support Qt4-Qt6, test Qt4.6 to Qt6.3 any version, any system and compiler.

This component is trouble-free 360 days 7 times 24 hours running in at least tens of thousands of sites, commercial grade quality assurance.

Each class corresponds to a complete and detailed usage example, with detailed annotations, which is very suitable for reading and learning.

It can be run as a stand-alone program, such as automatically cleaning up early data and synchronizing data to the cloud.

All threading, no card interface, automatically reconnect the database.

General test case, sqlite database, database generator inserts 1000 records per second for about 0.003 seconds, while automatically cleans up data classes and deletes 1000 records per second for about 0.13s. Different threads do not interfere with each other.

Third, experience address

Experience address: https://pan.baidu.com/s/15ZKAlptW-rDcNq8zlzdYLg extraction code: uyes file name: bin_dbtool.zip

Domestic site: https://gitee.com/feiyangqingyun

International site: https://github.com/feiyangqingyun

4. Effect picture

Related codes # include "frmdbhttp.h" # include "ui_frmdbhttp.h" # include "quihelper.h" # include "dbhelper.h" # include "dbhttpthread.h" frmDbHttp::frmDbHttp (QWidget * parent): QWidget (parent), ui (new Ui::frmDbHttp) {ui- > setupUi (this); this- > initForm (); this- > initConfig (); this- > initTable ();} frmDbHttp::~frmDbHttp () {delete ui } void frmDbHttp::showEvent (QShowEvent *) {static bool isShow = false; if (! isShow) {isShow = true; QTimer::singleShot (100,this, SLOT (on_btnStart_clicked ());}} void frmDbHttp::initForm () {ui- > frame- > setFixedWidth (AppConfig::RightWidth); QUIHelper::initTableView (ui- > tableWidget); maxCount = 100; currentCount = 0; timer = new QTimer (this); timer- > setInterval (1000) Connect (timer, SIGNAL (timeout ()), this, SLOT (on_btnDo_clicked (); / / instantiate network request data collection communication class dbHttp = new DbHttpThread (this); connect (dbHttp, SIGNAL (debug (QString)), this, SLOT (debug (QString)); connect (dbHttp, SIGNAL (error (QString)), this, SLOT (error (QString) Connect (dbHttp, SIGNAL (receiveData (QString, QStringList, int), this, SLOT (receiveData (QString, QStringList, int); / / set parameters dbHttp- > setUrl ("http://127.0.0.1:6000"); QMap tables; tables.insert (" NodeData "," PositionID,NodeValue,NodeStatus,SaveTime "); dbHttp- > setTables (tables);} void frmDbHttp::initConfig () {} void frmDbHttp::saveConfig () {} void frmDbHttp::initTable () {QStringList columnNames ColumnNames txtMain, 1, msg, maxCount, currentCount);} void frmDbHttp::receiveData (const QString & tag, const QStringList & data, int msec) {QString msg = QString ("time spent (% 1 second) identifies (% 2) data (% 3)") .arg (QString::number ((double) msec / 1000, 'fags, 3)) .arg (tag) .arg (data.join ("|")); QUIHelper::appendMsg (ui- > txtMain, 3, msg, maxCount, currentCount) / / display to table int count = data.count (); ui- > tableWidget- > setRowCount (count / columnCount); int row =-1; for (int I = 0; I

< count; i = i + columnCount) { row++; for (int j = 0; j < columnCount; ++j) { ui->

TableWidget- > setItem (row, j, new QTableWidgetItem (data.at (I + j));} void frmDbHttp::on_btnDo_clicked () {dbHttp- > select ("NodeData", "PositionID,NodeValue,NodeStatus,SaveTime");} void frmDbHttp::on_btnStart_clicked () {if (ui- > btnStart- > text () = = "start the service") {on_btnDo_clicked (); timer- > start () Ui- > btnStart- > setText ("stop the service");} else {timer- > stop (); ui- > btnStart- > setText ("start the service");}} void frmDbHttp::on_btnClear_clicked () {QUIHelper::appendMsg (ui- > txtMain, 0, ", maxCount, currentCount);} these are all the contents of the article" how to implement the general database request in the Qt database ". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report