qtsql

multiple sql statements in QSqlQuery using the sqlite3 driver

陌路散爱 提交于 2021-02-15 04:05:37
问题 I have a file containing several SQL statements that I'd like to use to initialize a new sqlite3 database file. Apparently, sqlite3 only handles multiple statements in one query via the sqlite3_exec() function, and not through the prepare/step/finalize functions. That's all fine, but I'd like to use the QtSQL api rather than the c api directly. Loading in the same initializer file via QSqlQuery only executes the first statement, just like directly using the prepare/step/finalize functions

Qt MySQL -----— Cannot open include file: 'mysql.h':

安稳与你 提交于 2021-01-28 10:20:49
问题 Im making a GUI application in Qt, it will be a front end to a database basically however i haven't even got to the point of doing anything yet because my database connection just keeps failing (Well it doesn't actually compile so its not a DB connection issue) Anyway my project wont even build because Qt gives the error: error: C1083: Cannot open include file: 'mysql.h': No such file or directory which i dont particularly understand because in the class that uses the QtSQL stuff i have

Qt MySQL -----— Cannot open include file: 'mysql.h':

心已入冬 提交于 2021-01-28 10:17:29
问题 Im making a GUI application in Qt, it will be a front end to a database basically however i haven't even got to the point of doing anything yet because my database connection just keeps failing (Well it doesn't actually compile so its not a DB connection issue) Anyway my project wont even build because Qt gives the error: error: C1083: Cannot open include file: 'mysql.h': No such file or directory which i dont particularly understand because in the class that uses the QtSQL stuff i have

Problem with QIBASE (firebird + Ubuntu)

孤者浪人 提交于 2020-01-03 03:50:06
问题 Good morning. I've tried to compile QIBASE driver to access FireBird database using sqlbrowser from %QTDIR/demos. But after i filled all fields in sqlbrowser and pushed OK button the program crashed with message: /opt/qt-everywhere-opensource-src-4.7.3/demos/sqlbrowser-build-desktop/sqlbrowser: symbol lookup error: /usr/lib/qt4/plugins/sqldrivers/libqsqlibase.so: undefined symbol: isc_attach_database To compile QIBASE driver i've done following steps: Installing FirebirdCS-2.5.0 to /opt

Qt SQL prepare fails

隐身守侯 提交于 2020-01-02 10:15:28
问题 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

Qt's model/view architecture

浪尽此生 提交于 2019-12-23 04:43:57
问题 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

How to load ODBC in qt

a 夏天 提交于 2019-12-22 10:13:48
问题 I'm very new to Qt and C++ I'm trying to connect to an ODBC db, but I'm getting the following output QSqlDatabase: QODBC driver not loaded QSqlDatabase: available drivers: QSQLITE How do I load ODBC in Qt . CODE : QString serverName = "LOCALHOST\\SQLEXPRESS"; QString dbName = "test"; QSqlDatabase db = QSqlDatabase::addDatabase("QODBC"); db.setConnectionOptions(); QString myCon = QString("DRIVER={SQL Native Client};SERVER=%1;DATABASE=%2;Trusted_Connection = Yes").arg(serverName).arg(dbName);

Qt QList<QString> serialization for database

别来无恙 提交于 2019-12-20 01:41:48
问题 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? 回答1: How about using QStringList instead of QList<QString> - QStringList numberList_; // instead of QList<QString>, use this QString myString1 = "Hello"; QString myString2 = "World"; numberList_ << myString1; numberList_ << myString2; QByteArray byteArray; QBuffer buffer(&byteArray); QDataStream out(&buffer); out

What is the correct way of QSqlDatabase & QSqlQuery?

烂漫一生 提交于 2019-12-14 00:15:14
问题 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

QSqlQueryModel with a parent - app crash

佐手、 提交于 2019-12-12 02:26:31
问题 I am rather new to Qt, maybe that's why I cant fully understand the child-parent concept. I need to perform some sql query. I set the QSqlQuery, perform the "prepare and bind" operation and exec it. Next I pass it to the model and display the data. The problem occurs when closing the window - I get a memory violation error. The error occurs only, when I create the model with a parent. Here's the code: QSqlQuery query; query.prepare(QString("SELECT \ %1 as nazwa \ , kontrahentid \ FROM