In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how to achieve Qt database collection, I believe that 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 understand it!
I. Preface
Database, as a data source, is widely used in many configuration software. specify the database type, fill in the database connection information, specify the corresponding database tables and fields, and the collection interval. The program automatically collects database data according to the collection interval, and the controls bound to the interface can be assigned and displayed. A great advantage of using a database as a data source is that there is no need to write additional communication code, and it has nothing to do with each other's language or platform, and there will be no wrangling. For example, incorrect parsing caused by incorrect communication protocols will support arbitrary languages and platforms. After all, there is a database as an intermediate carrier, and there will be databases in any language or platform. All are compatible, so using the database as the data source is a good solution, which can focus on the continuous integration of software functions.
Second, the functions realized
Automatically load all the controls in the plug-in file to generate a list, with more than 120 controls by default.
Drag to the canvas to automatically generate the corresponding control, WYSIWYG.
On the right side of the Chinese attribute bar, change the corresponding attributes immediately applied to the corresponding selected controls, intuitive and concise, very suitable for rookies to use.
The original attribute bar text translation mapping mechanism is extremely efficient, and it is very convenient to expand the attribute bar of other languages.
The properties of all controls are automatically extracted and displayed in the right property bar, including the enumerated value drop-down box.
Support manual selection of plug-in files, external import plug-in files.
You can export all control configuration information for the current canvas to a xml file.
You can manually select the xml file to open the control layout and automatically load the control according to the xml file.
Can pull the slider, check the analog data check box, text box input, three ways to generate data to apply all controls.
The control supports eight azimuth pull adjustments, adapts to any resolution, and fine-adjusts the position up and down the keyboard.
Through the serial port acquisition, network acquisition, database collection of three ways to set data.
The code is extremely concise, the comments are very detailed, and can be used as an embryonic form of configuration to expand more functions.
Pure Qt writing, support any Qt version + any compiler + any system.
Third, effect picture
4. Core code void frmData::initServer () {/ / instantiates serial port class, binds signal slot com = new QextSerialPort (QextSerialPort::EventDriven, this); connect (com, SIGNAL (readyRead ()), this, SLOT (readDataCom (); / / instantiates network communication client class, binds signal slot tcpClient = new QTcpSocket (this); connect (tcpClient, SIGNAL (readyRead ()), this, SLOT (readDataClient () / / instantiate the network communication server class, bind signal slot tcpSocket = NULL; tcpServer = new QTcpServer (this); connect (tcpServer, SIGNAL (newConnection ()), this, SLOT (newConnection (); / / start timer to read database collection data timer = new QTimer (this); connect (timer, SIGNAL (timeout ()), this, SLOT (readDataDb (); timer- > setInterval (1000) } void frmData::on_btnOpenDb_clicked () {if (ui- > btnOpenDb- > text () = = "open") {if (App::DbType = = "sqlite") {/ / first check whether the database file exists QString dbPath = qApp- > applicationDirPath () + "/" + App::DbPath; QFile file (dbPath) If (file.size () = = 0) {return;} dbConn = QSqlDatabase::addDatabase ("QSQLITE"); dbConn.setDatabaseName (dbPath) } else if (App::DbType = = "mysql") {/ / first check whether the database server IP is connected. If you do not check the direct connection, the IP that does not exist will card QTcpSocket socket; socket.connectToHost (App::DbPath, App::DbPort) for a long time; if (! socket.waitForConnected (2000)) {return } else {socket.disconnectFromHost ();} dbConn = QSqlDatabase::addDatabase ("QMYSQL"); dbConn.setHostName (App::DbPath); dbConn.setPort (App::DbPort); dbConn.setDatabaseName (App::DbName); dbConn.setUserName (App::DbUser); dbConn.setPassword (App::DbPwd) } else {/ / does not support other databases, so you can add return;} bool ok = dbConn.open (); if (ok) {setEnable (ui- > btnOpenDb, false); ui- > btnOpenDb- > setText ("off"); timer- > start () }} else {if (dbConn.isOpen ()) {dbConn.close ();} setEnable (ui- > btnOpenDb, true); ui- > btnOpenDb- > setText ("Open"); timer- > stop ();}} void frmData::readDataDb () {QString sql = QString ("select% 1 from 2") .arg (App::DbColumn) .arg (App::DbTable); QSqlQuery query If (query.exec (sql)) {if (query.next ()) {double value = query.value (0). ToDouble (); ui- > txtValue- > setText (QString::number (value)); append (4, QString ("current value:% 1") .arg (value)) } the above is all the contents of the article "how to achieve database collection in Qt". 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.