Navigation

    Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Search
    • Unsolved
    1. Home
    2. Tags
    3. qsqldatabase
    Log in to post

    • SOLVED How to insert Qxlsx data into sqlite database table?
      QML and Qt Quick • database qsqldatabase sqlite database qml qxlsx dat • • Joshika_Namani  

      16
      0
      Votes
      16
      Posts
      404
      Views

      @JonB sorry for that, insert into Dataset(AT) values(?): I know nothing about SQLite. Dataset(AT) is a (syntactically valid) table to insert into, is it? Yes, it is valid statement in sqlite. Also QSqlQuery::prepare() returns a bool for success/failure, which you should be checking. Returns true if the query is prepared successfully; otherwise returns false. Plus, you check QSqlDatabase::lastError() after QSqlQuery::exec() fails, but that says yes, I got error. like QSqlError("","",""); I checked again there was a problem in database but it solved thanks alot. Now, I'm able to insert data into database from QXlsx file.
    • UNSOLVED QMYSQL driver not found after release
      Qt 6 • qsqldatabase qmysql release driver not load sqldriver • • Persivan  

      2
      0
      Votes
      2
      Posts
      112
      Views

      @Persivan said in QMYSQL driver not found after release: Any ideas? Yes, use search function in this forum - this is asked so often. Most probably the MySQL driver lib is missing.
    • SOLVED Connection to remote SQL Server using Qt
      General and Desktop • qsqldatabase tcp sql server setdatabasename • • Touchoco  

      4
      0
      Votes
      4
      Posts
      367
      Views

      @artwaw Thanks a lot ! It works. I don't know how I could miss this one. It seems that every time I restart the server, the IP changes. I will have to set a fixed IP adress.
    • SOLVED How to properly share in-memory SQLite database among threads?
      General and Desktop • sqlite qsqldatabase multithreading • • akoch  

      5
      0
      Votes
      5
      Posts
      906
      Views

      I got it fixed, thanks to @Christian-Ehrlicher! I almost did not try your suggestion because I thought I knew very well where the warning comes from. But it turned out that I had missed a setQuery() call that was lacking its second parameter (the database connection to use).
    • SOLVED QSqlDatabase open() crashes when db cannot be accessed ?
      General and Desktop • qsqldatabase qpsql • • R-P-H  

      27
      0
      Votes
      27
      Posts
      585
      Views

      I have usually seen processEvent called from the main thread directly which forces processing of events however calling it from a different thread is the first time. As you can see there's some strange interaction. I currently wonder whether you have an event that is processed by the wrong event loop.
    • SOLVED QSqlTableModel() empty on Ubuntu but works on Windows ?
      General and Desktop • qsqltablemodel qsqldatabase postgresql • • R-P-H  

      41
      0
      Votes
      41
      Posts
      1422
      Views

      Upgrading to Qt Version 5.15+ solved the issue.
    • UNSOLVED Can't write into database
      General and Desktop • qml qsqldatabase qsql • • Babs  

      14
      0
      Votes
      14
      Posts
      385
      Views

      @Babs Anytime. Please don't forget to mark the thread as "solved".
    • UNSOLVED QSqlquery exec timeout
      General and Desktop • qsqldatabase qsqlquery qt 5.12 exec timeout • • BartoszPaj  

      5
      0
      Votes
      5
      Posts
      597
      Views

      Process still block, when I lost connection.
    • UNSOLVED QSqlDatabase and upgrade to Qt5.12
      General and Desktop • qsqldatabase threads qt5.9 qt5.12 • • Alain38 0  

      2
      0
      Votes
      2
      Posts
      165
      Views

      @Alain38-0 said in QSqlDatabase and upgrade to Qt5.12: Unfortunately with Qt5.12 nothing works. Because the database must be now in the same thread that the process using it. I'm surprised it used to work at all. So far as I understood, it was always the case that database access had to be in same thread as where database created.
    • UNSOLVED Oracle OCI Result cannot bind to return a SYS_REFCURSOR
      General and Desktop • qsqldatabase qsql sqldriver oracle qt 5.13.0 • • Redstar123  

      1
      0
      Votes
      1
      Posts
      161
      Views

      No one has replied

    • SOLVED How to share database connection parameters between multiple QSqlTableModel objects?
      QML and Qt Quick • database qsqltablemodel qsqldatabase models model binding • • ivarec  

      6
      0
      Votes
      6
      Posts
      771
      Views

      From the looks of it, you have to re-create the models when you change these settings.
    • SOLVED Receiving multiple result sets of return value in SQL server stored procedure from Qt (QSqlQuery)
      General and Desktop • qsqldatabase qsqlquery odbc sqlserver qodbc • • alizadeh91  

      17
      0
      Votes
      17
      Posts
      2989
      Views

      @SGaist I did it this way for reading return params: Query.nextResult(); // after reading table values //Get Return Parameter for (int i=0; i<CountReturnParam; i++) { qDebug() << QString("Returnparam %1 = %2") .arg(i).arg(Query.boundValue(i).toString()); }
    • UNSOLVED QSqlite not able to retrieve data
      General and Desktop • qsqldatabase • • SolaVitae  

      2
      0
      Votes
      2
      Posts
      637
      Views

      Hi, What version of Qt are you using ? You should print the error you get if exec fails. That will give you clues as to what is happening. On a side note, QString already provides easy to use arguments handling so you don't have to use snprintf.
    • SOLVED QT5.9.1 connect MySQL5.7.18
      General and Desktop • mysql qsqldatabase mac os x connection • • LuAria  

      12
      0
      Votes
      12
      Posts
      2805
      Views

      @jsulm Thanks a lot! Sorry for my miss on the link. I will try it.
    • SOLVED lost SQL DB connection
      3rd Party Software • mysql qsqldatabase connect problem • • koahnig  

      5
      1
      Votes
      5
      Posts
      2807
      Views

      @koahnig Well the "MySQL server has gone away" msg also seems slightly "wooden" so it fits perfectly :)
    • UNSOLVED What is the problem in QSqlQuery?
      General and Desktop • qsqldatabase qsqlquery qtsql • • _compiler  

      11
      0
      Votes
      11
      Posts
      2693
      Views

      @_compiler Ok, i see, its a helper class. Well you need to open a db then. You dont need to do it in QueryBuilder. If you open a db in main , QSqlQuery will use this DB. You dont need pointer or reference. Its handled internally.
    • SOLVED QSqlDatabase : Driver not loaded Driver not loaded
      Mobile and Embedded • android qsqldatabase driver not load android studio • • Sanders  

      4
      0
      Votes
      4
      Posts
      1878
      Views

      Glad you found out and thanks for sharing ! Since you have it working now, please mark the thread as solved using the "Topic Tools" button so that other forum users may know a solution has been found :)
    • UNSOLVED QSqlDatabase warning message
      General and Desktop • qsqldatabase • • gabor53  

      6
      0
      Votes
      6
      Posts
      1832
      Views

      To add to @the_ , if you only have one database connection and don't give it a name, it becomes the default connection and you don't need to call QSqlDatabase::database each time you make a query.
    • SOLVED Advice on adding threading in database application
      General and Desktop • qsqldatabase qsqlquery threading • • panosk  

      10
      0
      Votes
      10
      Posts
      6502
      Views

      @panosk and to be honest I had already started work on this You already have that in QSqlDatabase, you only need to keep track of the connections' names. Good luck!
    • UNSOLVED QSqlDatabase - Connection failed
      Italian • qsqldatabase • • Ottaviane  

      3
      0
      Votes
      3
      Posts
      859
      Views

      @Ottaviane said: Crea un link alla con il comando ln : ln -s /usr/lib64/libmysqlclient.so.18.0.0 /usr/lib64/libmysqlclient_r.so
    • UNSOLVED ODBC driver not loaded but ODBC is available according to QSqlDatabase class
      Installation and Deployment • qsqldatabase odbc • • cristiano.narcisi  

      2
      0
      Votes
      2
      Posts
      1216
      Views

      Hi, I got the libqsqlodbc.so plugin to load successfully, I think it was last year with Qt 5.2 or 5.3, but I remember I had same kind of difficulties because the libqsqlodbc.so plugin is depending on libodbc.so being in the correct place. You could check with ldd libqsqlodbc.so to see what .so files are missing..
    • SOLVED QSqlDatabase: QMYSQL driver not loaded
      General and Desktop • qsqldatabase ubuntu 14.04 qmysql driver not load • • Tas-sos  

      28
      0
      Votes
      28
      Posts
      22846
      Views

      @Gualtix Hi and welcome to devnet, you are not following the current documented procedure.
    • SOLVED Improve efficiency of database connection
      General and Desktop • qsqldatabase qsqlquery • • reezeus  

      10
      0
      Votes
      10
      Posts
      2413
      Views

      Done :)
    • SOLVED QThreadPool and QSqlDatabase
      General and Desktop • qthread sql qsqldatabase qthreadpool • • antreimer  

      5
      1
      Votes
      5
      Posts
      2846
      Views

      I'm using this code on the server. By blocking I simply meant that if one client requested something that took long to process it shouldn't block the other clients. I may upload a working sample of this code to github later.
    • SOLVED qsqldatabase sqlite - how to set temp directory
      General and Desktop • c++ qt5.5 sqlite qsqldatabase • • phirestalker  

      9
      0
      Votes
      9
      Posts
      2961
      Views

      for anyone else who wants to know how to do it, this is what I did. add this to one of you header files #include <sqlite3.h> #include <QSqlDriver> add this to your .pro file INCLUDEPATH += $$[QT_INSTALL_PREFIX]/src/3rdparty/sqlite SOURCES += $$[QT_INSTALL_PREFIX]/src/3rdparty/sqlite/sqlite3.c and in your MainWindow.cpp file add sqlite3_temp_directory = path-to-dir; IMPORTANT if you used homebrew to install qt5, they do NOT install the sources, you will have to downloaded the sources from the qt.io website extract and copy the qtbase/src folder to wherever $$[QT_INSTALL_PREFIX] is. also this does compile, but I haven't tested to see if the files actually get stored where I set, so...
    • UNSOLVED Update QSqlTableModel after QSqlQuery executing
      General and Desktop • qsqltablemodel qsqldatabase qsqlquery filtering • • EskeHagen  

      4
      0
      Votes
      4
      Posts
      2474
      Views

      Adapted from the documentation example: model->setFilter("should_alarm=1");
    • UNSOLVED What is the purpose of the QSqlDatabase connection name?
      General and Desktop • qsqldatabase connection name • • sarai  

      5
      0
      Votes
      5
      Posts
      2365
      Views

      Hi, @sarai Yes QFile does: it's the file name. QSqlDatabase allows you to handle one or more database connections through multiple possible drivers at the same time in a easy to use fashion. The design avoids you to have to create a QSqlDatabase instance and setting it up again and again in each class/function of your application where you would like to run a query. That also means that you don't have to put your credentials everywhere in your application. That way, you can easily get the connection you need in a multi database setup.
    • UNSOLVED QSqlDatabase: QMYSQL driver not loaded QSqlDatabase: available drivers: QSQLITE QMYSQL QPSQL QMYSQL3 QPSQL7 on ubuntu
      General and Desktop • mysql qsqldatabase drivers not loaded • • KrysTabaro  

      4
      0
      Votes
      4
      Posts
      1244
      Views

      @surendar-dharani there's no need to do necro-posting when you are already getting answers on your thread.
    • UNSOLVED Qt5 QSqlDatabase: read PL/SQL variable from oracle
      General and Desktop • sql qsqldatabase variable oracle • • Hans Hupe  

      2
      0
      Votes
      2
      Posts
      1751
      Views

      I'm not familiar with Oracle, but this looks close enough to Postgresql that I'll show how I would do it in PG/SQL in hopes that it will be useful. I would create the function in the database CREATE OR REPLACE FUNCTIOM test_fucntion(_name TEXT) RETURNS BIGINT AS $BODY$ DECLARE _rv BIGINT BEGIN INSERT INTO test_table(name) VALUES(_name) RETURNING id into _rv; RETURN _rv; END; $BODY$ LANGUAGE plpgsql; After adding that function to the database you can simply execute the query SELECT * from test_function("name"); to get your ID. As I said, this is Postgres code, but I'm pretty sure the Postgres authors imitated Oracle to some extent. Mike
    • How to patch 'QSqlDatabase::open always returns true with QMYSQL'
      Installation and Deployment • cmake qsqldatabase clion-ide archlinux • • richin13  

      8
      0
      Votes
      8
      Posts
      2825
      Views

      You're welcome ! Since everything is working now, please mark the thread as solved so other forum users may know a solution has been found :)
    • [Solved] QSqlDatabase: Insert values from a database to another
      General and Desktop • sql database sqlite qsqldatabase qsqlquery qsql qtsql sqlite database qsqlite • • Alberto  

      5
      0
      Votes
      5
      Posts
      3700
      Views

      At the end it was a typo. I was trying to insert a value into a column called Localización by using: guardar_s.prepare("INSERT INTO Solicitudes_Trabajo (Localizacion) The problem is in the accent mark. So if anyone gets this error, watch out the typos. Thanks @clochydd !
    • [Resuelto] QSqlDatabase: Insertar valores de una base de datos a otra
      Spanish • sql database sqlite qsqldatabase qsql qtsql sqlite database qsqlite base de datos • • Alberto  

      3
      0
      Votes
      3
      Posts
      4061
      Views

      Al final guardando cada valor de las dos bases de datos en QStrings funcionaba: QString _Telefono = seleccionar2.value(8).toByteArray().constData(); QString _Tecnico_Asignado = seleccionar2.value(0).toByteArray().constData(); QString _Estado_Solicitud = seleccionar2.value(7).toByteArray().constData(); Así podía usar este código sin problema: QSqlQuery guardar_s; guardar_s.prepare("INSERT INTO Solicitudes_Trabajo (N_Solicitud, Fecha_Emision, Unidad_Hospitalaria," "Codigo_Equipo, Equipo, Marca)" "VALUES (:N_Solicitud, :Fecha_Emision, :Unidad_Hospitalaria, :Codigo_Equipo, :Equipo," ":Marca)"); guardar_s.bindValue(":N_Solicitud", _N_Solicitud); guardar_s.bindValue(":Fecha_Emision", _Fecha_Emision); guardar_s.bindValue(":Unidad_Hospitalaria", _Unidad_Hospitalaria); guardar_s.bindValue(":Codigo_Equipo", _Codigo_Equipo); guardar_s.bindValue(":Equipo", _Equipo); guardar_s.bindValue(":Marca", _Marca); Insertaba los valores de las dos bases de datos en la base Empresa, pero si usaba este otro con más valores no funcionaba: QSqlQuery guardar_s; guardar_s.prepare("INSERT INTO Solicitudes_Trabajo (N_Solicitud, Fecha_Emision, Unidad_Hospitalaria, Codigo_Equipo," "Equipo, Marca, Modelo, N_Serie, Localizacion, Unidad_Tecnica, Peticionario, Telefono, " "Descripcion_Solicitud, Tecnico_Asignado, Tipo_Solicitud, Estado_Solicitud) " "VALUES (:N_Solicitud, :Fecha_Emision, :Unidad_Hospitalaria, :Codigo_Equipo, :Equipo, :Marca, :Modelo," ":N_Serie, :Localizacion, :Unidad_Tecnica, :Peticionario, :Telefono, :Descripcion_Solicitud," ":Tecnico_Asignado, :Tipo_Solicitud, :Estado_Solicitud)"); guardar_s.bindValue(":N_Solicitud", _N_Solicitud); guardar_s.bindValue(":Fecha_Emision", _Fecha_Emision); guardar_s.bindValue(":Unidad_Hospitalaria",_Unidad_Hospitalaria); guardar_s.bindValue(":Codigo_Equipo", _Codigo_Equipo); guardar_s.bindValue(":Equipo", _Equipo); guardar_s.bindValue(":Marca", _Marca); guardar_s.bindValue(":Modelo", _Modelo); guardar_s.bindValue(":N_Serie", _N_Serie); guardar_s.bindValue(":Localizacion", _Localizacion); guardar_s.bindValue(":Unidad_Tecnica", _Unidad_Tecnica); guardar_s.bindValue(":Peticionario", _Peticionario); guardar_s.bindValue(":Telefono", _Telefono); guardar_s.bindValue(":Descripcion_Solicitud", _Descripcion_Solicitud); guardar_s.bindValue(":Tecnico_Asignado", _Tecnico_Asignado); guardar_s.bindValue(":Tipo_Solicitud", "a"); guardar_s.bindValue(":Estado_Solicitud", _Estado_Solicitud); Me daba el error: 12.ERROR: QSqlError("", "Parameter count mismatch", ""). Pensaba que quizás eran demasiados valores para Qt Creator. Pero al final, después de muchas pruebas me dí cuenta que estaba intentando insertar un valor en la columna existente Localización con un INSERT INTO Solicitudes_Trabajo (Localizacion). Lo explico por si a alguien más le sale ese mismo error que pruebe a revisar todos los campos y columnas en busca de algún pequeño fallo en alguna letra o alguna tilde.
    • [Solved] Help Databases QtSql
      General and Desktop • database sqlite qsqldatabase qsqlquery qsql qtsql sqlite database qsqlite • • Alberto  

      5
      0
      Votes
      5
      Posts
      2251
      Views

      Solved. I tried a lot of things to solve the problem. Some of them included calling next before accessing the result as @SGaist said, but it continued saying: QSqlQuery::value: not positioned on a valid record At last I created a new project with a new database and it worked properly with this code: hospital=QSqlDatabase::addDatabase("QSQLITE"); hospital.setDatabaseName("C:/Sqlite3/Hospital.sqlite"); if(hospital.open()){ qDebug()<<"4.Se ha conectado a la base de datos Hospital"; }else{ qDebug()<<"4.ERROR. No se ha conectado a la base de datos Hospital"; } QSqlQuery mostrar; mostrar.prepare("SELECT*FROM Partes WHERE N_Parte=:ID"); mostrar.bindValue(":ID",ui->lineEditN_Parte->text()); if(mostrar.exec()) { qDebug()<<"5.Los datos del parte se han mostrado correctamente"; }else{ qDebug()<<"5.ERROR. Los datos del parte no se han mostrado correctamente"; qDebug()<<"5.ERROR:"<<mostrar.lastError(); } mostrar.next(); ui->tableWidget->setRowCount(15); QStringList Campos; Campos<<"Fecha de Emisión"<<"Unidad Hospitalaria"; ui->tableWidget->setVerticalHeaderLabels(Campos); ui->tableWidget->insertColumn(0); ui->tableWidget->setColumnCount(1); ui->tableWidget->setItem(0, 0, new QTableWidgetItem(mostrar.value(1).toByteArray().constData())); ui->tableWidget->setItem(2, 0, new QTableWidgetItem(mostrar.value(2).toByteArray().constData())); So I guess the problem was in the database, maybe in the columns, maybe in the rows, maybe in the values or maybe in the name of each of them. The important thing is that the code I post in this reply works perfectly, so if anyone has a similar problem I hope it helps. Thank you very much!
    • [Resuelto] Bases de datos QtSql
      Spanish • sql qtablewidget database sqlite qsqldatabase qsqlquery qtsql sqlite database qsqlite base de datos • • Alberto  

      4
      0
      Votes
      4
      Posts
      4371
      Views

      Resuelto. Intenté muchas cosas para solucionar el problem, algunas incluian la utilización de next() que me faltaba en el código de mi respuesta anterior pero continuaba saliendo el error: QSqlQuery::value: not positioned on a valid record Al final creé un nuevo proyecto con una base de atos nuevas y funciona correctamente con este código: hospital=QSqlDatabase::addDatabase("QSQLITE"); hospital.setDatabaseName("C:/Sqlite3/Hospital.sqlite"); if(hospital.open()){ qDebug()<<"4.Se ha conectado a la base de datos Hospital"; }else{ qDebug()<<"4.ERROR. No se ha conectado a la base de datos Hospital"; } QSqlQuery mostrar; mostrar.prepare("SELECT*FROM Partes WHERE N_Parte=:ID"); mostrar.bindValue(":ID",ui->lineEditN_Parte->text()); if(mostrar.exec()) { qDebug()<<"5.Los datos del parte se han mostrado correctamente"; }else{ qDebug()<<"5.ERROR. Los datos del parte no se han mostrado correctamente"; qDebug()<<"5.ERROR:"<<mostrar.lastError(); } mostrar.next(); ui->tableWidget->setRowCount(15); QStringList Campos; Campos<<"Fecha de Emisión"<<"Unidad Hospitalaria"; ui->tableWidget->setVerticalHeaderLabels(Campos); ui->tableWidget->insertColumn(0); ui->tableWidget->setColumnCount(1); ui->tableWidget->setItem(0, 0, new QTableWidgetItem(mostrar.value(1).toByteArray().constData())); ui->tableWidget->setItem(2, 0, new QTableWidgetItem(mostrar.value(2).toByteArray().constData())); Así que supongo que el problema estaba en la base de datos anterior, quizás en las columnas, quizás en las filas, quizás en los valores o quizás en el nombre de cada uno de estos elementos. Lo importante es que el código que adjunto en esta respuesta funciona correctamente, de modo que si alguien tiene un problema parecido espero que esto le ayude. Muchas gracias!
    • Embedded MySQL server
      General and Desktop • qsqldatabase qmysql • • SebastianS  

      9
      0
      Votes
      9
      Posts
      3641
      Views

      Note on https://dev.mysql.com/doc/refman/5.7/en/libmysqld.html says: “The libmysqld embedded server library is deprecated as of MySQL 5.7.17 and will be removed in MySQL 8.0.“
    • QSqlDatabase known connection issue: QSqlDatabasePrivate::removeDatabase: connection 'qt_sql_default_connection' is still in use, all queries will cease to work.
      General and Desktop • qsqldatabase • • Jorge  

      6
      0
      Votes
      6
      Posts
      2935
      Views

      @ChrisW67 Thank you. I kind of understand what you mean, but recently I tried a solution that appears to work. I have a class named mainWidget, in which the remaining widgets are instantiated. I simply retrieve the db connection name, store it in a variable and then whenever I switch widgets and need to re-open the database, I close said connection and addDatabase again. I am guessing this is not optimal, but it allows me to move on with the SQLite databases.
    • QSqlRelationalTableModel - problem with non-existent rows
      General and Desktop • mysql qsqldatabase qsqlrelationalt • • Stravinsky  

      1
      0
      Votes
      1
      Posts
      513
      Views

      No one has replied

    • QSqlite driver does not load
      General and Desktop • sql plugin desktop deployment sqlite dll qsqldatabase driver • • Tuby1  

      20
      0
      Votes
      20
      Posts
      16472
      Views

      @danks_ That is good to hear ! Could also been some kind of setup problem with 5_5 but yeah it does seems like a bug. I will try with 5_5 and see it it fails for me too. update: Tested win pure 5_5 install It worked by copying the DLLs ! ? Even worked with no sub sqldrivers folder ...! (in the release folder) But when moved out of the virtual machines it did want the sqldrivers folder to work. So the current version of 5.5 via the online installer does seems to work in regards to sql.?!
    • Sorcery/weird thing happening including QSqlDatabase [SOLVED]
      General and Desktop • qsqldatabase • • Robey Mardon  

      3
      0
      Votes
      3
      Posts
      885
      Views

      Hi, No black magic here, I'd say you added the sql module to your pro file but didn't run qmake before building.