天道酬勤,学无止境

qtsql

Qt's model/view architecture

After making connection with the database , I have written the following code, but after execution view's inner cells are empty. WHy? enum { name = 0, clas = 1, launched = 2 }; QSqlTableModel* model = new QSqlTableModel; model->setTable("ships"); model->setSort(name, Qt::AscendingOrder); model->setHeaderData(name, Qt::Horizontal, "Name"); model->setHeaderData(clas, Qt::Horizontal, "class"); model->setHeaderData(launched, Qt::Horizontal, "launched"); model->select(); QTableView * view = new QTableView; view->setModel(model); view->setSelectionMode(QAbstractItemView::SingleSelection); view-

2021-07-03 10:44:44    分类:问答    qt   linq-to-sql   qtsql

Qt SQL prepare fails

I'm trying to run this Qt code QString serverName = "localhost"; QString dbName = "zfserver"; QString userName = "root"; QString passWord = "123456"; QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL"); db.setConnectOptions(); db.setHostName(serverName); db.setDatabaseName(dbName); db.setUserName(userName); db.setPassword(passWord); if(db.open()) { QSqlQuery query; query.prepare("INSERT INTO account (name, email, password, type) " "VALUES (:name, :email, :password, :type)"); query.bindValue(":name", "atef"); query.bindValue(":email", "asfasf@gfasga.com"); query.bindValue(":password", "123")

2021-06-26 01:28:12    分类:问答    c++   sql   qt   qtsql

How to make Qt aware of the QMYSQL driver

I'm trying to access a MySql database from a Qt application but I get the following error: QSqlDatabase: QMYSQL driver not loaded QSqlDatabase: available drivers: QSQLITE QSQLITE2 I find this very strange cause I have libqsqlmysql.so on my Qt folder. I have even tried to compile the MySql driver as a static plugin and add it to my .pro file as: QTPLUGIN += qsqlmysql But this also generates the same runtime error (it must've found the plugin cause there's no error compiling the application) What am I missing? I would like to avoid having to compile Qt from source cause this will have to work

2021-06-14 10:54:53    分类:问答    qt   qtsql

QtSql 应用程序无法在部署的机器上运行(QtSql application not working on the deployed machine)

问题 我用 Qt/C++ 制作了一个软件。 我需要在Windows 7(64位)上部署它,这也是我开发软件的主机。 问题是我的软件可以与开发机器上的 sqlite 数据库交互,但是当我尝试在其他机器上部署我的软件时,它无法与那里的数据库交互。 我也尝试使用“以管理员身份运行”,但没有帮助。 我也尝试使用兼容模式。 数据库位于本地C:\Users\username\Desktop\db1.sqlite ,因此我的软件不需要网络或互联网即可正常运行。 我还在我的软件中包含了QtGui4 、 QtCore和QtSql4 dll。 有人可以指出这里可能出了什么问题吗? 回答1 是的,所以在提供解决方案之前,这里有几件事需要讨论,即: 1) 当您在 Windows 机器上开发软件并且它工作得很好,但不是在您部署软件的机器上时,首先要检查的是依赖关系。 他们都正确运送吗? 我该如何去检查它? 嗯,这就是免费提供的依赖步行器的目的。 您必须在部署软件的机器上运行; 换句话说,在部署之后。 如果它在那里工作,请不要在开发机器上运行它。 好的,这是关于调试的,所以让我们具体了解 Qt... 2)您正在使用 QtSql 模块来处理 Qt 应用程序中很好的数据库交互。 然而,主要的动态库,又名。 QtSql4.dll 是关于抽象功能的。 也就是说,所有 Qt 代码都不会处理特定的驱动程序本身。

2021-06-12 07:21:28    分类:技术分享    c++   windows   qt   sqlite   qtsql

parameter count mismatch in parameterized query

I am using quite a lot of parameterized queries in my code for performance reasons. In short, some of them work, some don't. I initialize the query during construction of my database wrapper like this: QString querystring = QString("SELECT somevalue FROM sometable " "WHERE one_feature = :one_feature AND other_feature = :other_feature "); myquery = QSqlQuery(db); myquery.setForwardOnly(true); myquery.prepare(querystring); myquery is a QSqlQuery member variable of my database wrapper. Later on, in the function that wants to use this query, I do something like int db_wrapper::fetch_some_value

2021-05-11 14:31:47    分类:问答    c++   qt   sqlite   qtsql

Qt QList<QString> serialization for database

I have a QList list. I want to insert it on the database. I didn't find any serializer method after some googling. If there any method / idea to serialize the list data for database?

2021-05-08 20:34:49    分类:问答    qt   serialization   qtsql

如何在where子句中使用别名? [复制](How do I use alias in where clause? [duplicate])

问题 这个问题已经在这里有了答案: 8年前关闭。 可能重复: 在WHERE子句中引用列别名 SELECT Trade.TradeId, Isnull(Securities.SecurityType,'Other') SecurityType, TableName, CASE WHEN SecurityTrade.SecurityId IS NOT NULL THEN SecurityTrade.SecurityId ELSE Trade.SecurityId END AS PricingSecurityID, sum(Trade.Quantity)OVER(Partition by Securities.SecurityType, SecurityTrade.SecurityId,Trade.Price, Buy,Long ) as sumQuantity, --added porfolio id for Getsumofqantity Trade.PortfolioId, Trade.Price, case when (Buy = 1 and Long = 1) then 1 when (Buy = 0 and Long = 0) then 1 else 0 end Position from Fireball_Reporting..Trade where porfolioid

2021-04-23 09:11:41    分类:技术分享    sql   sql-server   qtsql

What is the correct way of QSqlDatabase & QSqlQuery?

I got confused with the manual , should i work like this: { QSqlDatabase db = QSqlDatabase::addDatabase (...); QSqlQuery query (db); query.exec (...); } QSqlDatabase::removeDatabase (...); As the document points out, query or db will be deconstructed automatically. But is that efficient ? Well , if i cache db inside a class , like the following: class Dummy { Dummy() { db = QSqlDatabase::addDatabase (...); } ~Dummy() { db.close(); } bool run() { QSqlQuery query (db); bool retval = query.exec (...); blabla ... } private: QSqlDatabase db; }; Sometimes i could see warnings like

2021-04-22 02:47:13    分类:问答    database   qt   qt4   qtsql

How do I use alias in where clause? [duplicate]

This question already has answers here: Closed 8 years ago. Possible Duplicate: Referring to a Column Alias in a WHERE Clause SELECT Trade.TradeId, Isnull(Securities.SecurityType,'Other') SecurityType, TableName, CASE WHEN SecurityTrade.SecurityId IS NOT NULL THEN SecurityTrade.SecurityId ELSE Trade.SecurityId END AS PricingSecurityID, sum(Trade.Quantity)OVER(Partition by Securities.SecurityType, SecurityTrade.SecurityId,Trade.Price, Buy,Long ) as sumQuantity, --added porfolio id for Getsumofqantity Trade.PortfolioId, Trade.Price, case when (Buy = 1 and Long = 1) then 1 when (Buy = 0 and Long

2021-04-04 15:27:41    分类:问答    sql   sql-server   qtsql