Skip to content
  • 0 Votes
    10 Posts
    1k Views
    M
    @JonB said in Qt Mysql [Mysql Server has gone away] and Silent failures after query exec(): @mvsri said in Qt Mysql [Mysql Server has gone away] and Silent failures after query exec(): like 10+ hours any statements like update or insert doesn't work. This may be significant. From your INSERT example you are using prepare() and you are binding variables. Please read https://forum.qt.io/topic/107690/lost-connection-to-mysql-server-during-query-qmysql3-unable-to-reset-statement carefully. There the suggestion is that this may fail to reconnect even with the reconnection option. If your problem is reproducible can you, at least temporarily/as a test change to make the query a string with whatever in it and abandon preparation and variable substitution? Does that make the problem go away? Furthermore, you check the result of exec() but when you do use prepare() you do not check the result it returns. You should do so. That may reveal an error at that stage. Also, given that abandonment of MYSQL_OPT_RECONNECT has either happened or is about to happen, you might remove this from your code and do whatever you have to manage reconnection yourself, to see whether that improves the situation. I do not know why your other audit log connection appears to work while your main one fails. Even more complex is your "writes to MySQL via QtConcurrent::run". I was under the impression that Qt requires you to write to a SQL connection from the same thread as where it was created/currently lives, won't QtConcurrent::run() break precisely that rule? Yet that one works. Who knows?! I have gone through this thread: https://forum.qt.io/topic/107690/lost-connection-to-mysql-server-during-query-qmysql3-unable-to-reset-statement/6. In my case, I’ve been using QString to build the query and pass it to the functions in databaseconnector class and passing it to QSqlQuery. To recreate the issue, I restarted the MySQL server from Services (windows), and I received the same error: Lost connection to MySQL server during query QMYSQL: Unable to execute query" (:0, ) After this, I implemented reconnection logic that attempts to reconnect if QSqlQuery::exec() fails and give connection error. When I recreated the same scenario (restarting the MySQL server), the reconnection worked as expected. Based on suggestions and further reading of the documentation, I’ve also modified my code to avoid holding the QSqlDatabase instance as a class variable and instead use it as a function-local variable. Regarding the AuditLogger class, I’ve completely reimplemented it and now use QMetaObject::invokeMethod for logging operations. While reviewing the documentation and googling for MYSQL_OPT_RECONNECT, it appears this option may no longer work as expected with recent versions. So, I’m considering removing it from the code. One pending task is to check the MySQL server logs—I haven’t received them yet, but once I do, I’ll analyze them for further insight. One doubt I have is: The system where the application is running is part of a domain network, governed by Group IT policies, and has antivirus installed. Could this environment be a potential cause for the dropped connection? (I understand this might be a naive question, but I’d like to rule out any possible cause.) Thank you again for your inputs—they’ve helped clarify several concepts for me.
  • How to check if MySQL connection is alive?

    Solved General and Desktop mysql connect alive
    2
    0 Votes
    2 Posts
    325 Views
    SGaistS
    Hi, One possible thing you could try is grab the database handle and use the mysql_ping method. Haven't done it myself so I can't guarantee
  • qt-cmake: command not found

    Unsolved Installation and Deployment qmysql qt6 cmake mysql mariadb
    17
    0 Votes
    17 Posts
    4k Views
    JonBJ
    @MH24 It vaguely, vaguely rings a bell that you have to do something special about root, possibly to do with how MySQL gets installed initially. Lots of hits for Googling mysql root localhost permission. I may have done the stuff mentioned in https://stackoverflow.com/a/46908573 in the past. (Be careful you don't lock yourself out, however!) But in any case what you have done now is better, as @Christian-Ehrlicher said you should not be using root user for your application.
  • Qt MySQL does not support TLS 1.2

    Unsolved General and Desktop mysql tls
    2
    0 Votes
    2 Posts
    491 Views
    Christian EhrlicherC
    See https://bugreports.qt.io/browse/QTBUG-84797 MYSQL_OPT_SSL_MODE is not yet added and when it will only be added for Qt6.6 and higher.
  • 0 Votes
    4 Posts
    2k Views
    Christian EhrlicherC
    Then please mark this topic as solved, thx.
  • QT6.3+mysql8.0+Mac

    Unsolved Qt 6 mysql qt6.3.0 mac os
    3
    0 Votes
    3 Posts
    698 Views
    W
    @JonB thx. I input was wrong.
  • 0 Votes
    9 Posts
    1k Views
    Christian EhrlicherC
    It's or sure no problem of Qt or the QSqlTableModel - fix your access rights.
  • how to insert and dipslay data from dateTimeEdit

    Unsolved General and Desktop python3 pyqt5 mysql
    4
    0 Votes
    4 Posts
    705 Views
    VRoninV
    Yes, Qt.EditRole and Qt.DisplayRole are the same thing in non-customised Qt classes
  • 0 Votes
    4 Posts
    807 Views
    JonBJ
    @lanas Yes to all of that, by all means read that overview link. I didn't say that "will be hard to retrive data from data base if i did not work with qtsql classes". Using the Python SQL classes instead would be fine for retrieving data from the database. But when you want to display that data in your Qt UI, rows & columns from your SQL queries, that will require some coding to get the Python-SQL-fetched-data to the Qt UI widgets and back. Whereas if you use the Qt classes they fill Qt models directly, and those are what Qt QTableViews use to display (and even edit) data. In the simplest case, see if you can't use Qt's QSqlTableModel for attaching your data retrieval to the database. That will have the necessary SELECT/INSERT/UPDATE/DELETE automatically generated/issued for you for working on a SQL table in the database, without you having to write the SQL statements like you tried to in your question. And attaching a QTableView to the QSqlTableModel will display what you fetched without any code. And it can even allow you/the user to edit the data in the table and write ot back to the database for you.
  • 0 Votes
    5 Posts
    1k Views
    M
    @Christian-Ehrlicher said in building qsqlmysql.dll for msvc error: Forgot to copy or typo? I forgot to copy. I looked into Makefile.Release and realised that instead of C:\mysql\include this It was including this C:\Program Files\MySQL\MySQL Server 8.0\include I deleted qmake.stash and config.cache and repeated the qmake again and this time I generated qsqlmysql.dll successfully. Tested it with Sample Cpp code in Qt, it's working. @Christian-Ehrlicher Thanks for the suggestion.
  • Unable to build Qt MySQL Driver

    Unsolved Mobile and Embedded android mysql mariadb sql
    3
    0 Votes
    3 Posts
    713 Views
    M
    Guys; May you please some help. I reached to a dead end
  • How use MYSQL on QT

    Unsolved General and Desktop qt 5.12 mysql plugin plugin install
    2
    0 Votes
    2 Posts
    1k Views
    Christian EhrlicherC
    @vin212 said in How use MYSQL on QT: MySql .................................. no ... I continue, i try this commande : nmake Why? As you can see qmake did not find your libs, so why do you think 'nmake' will do anything for mysql? As written in the documentation look into the logs and see why the libs were not found or usable.
  • 0 Votes
    6 Posts
    1k Views
    T
    ended up having to walk through dependency walker to solve as some necessary dll files were not where they needed to be.
  • Connect to MYSQL failed in Qt

    Unsolved General and Desktop qt6 c++ mysql mysql server
    33
    0 Votes
    33 Posts
    7k Views
    E
    @SGaist ok lemme try,if i understand what documentation say lol
  • QT MySQL Databese connect fail

    Solved General and Desktop mysql database qt5.9.2 c++ localhost
    4
    0 Votes
    4 Posts
    857 Views
    E
    @Christian-Ehrlicher yes,i just realize i forget to add sql to QT += core gui sql thanks for respone anyway
  • 0 Votes
    7 Posts
    2k Views
    J
    I did the migration with mysqldump then I edited the dump file. Then I have the resulting file into sqlite and saved it as database. The date columns are now stored in sqlite as TEXT fields. All done on a linux machine. Thank you VRonin for your suggestion. That sounds like a great idea. Can I do this in pyQt5 or do I need to go to C++? I think QSQLiteDriver is a plugin i.e. a shared library. That means I have to do this in C++. Is that right? I wanted to avoid C++ so that my application is more portable. But anyway this solution sounds great. Thanks for you answers guys.
  • SQLite database creation

    Solved General and Desktop sqllite mysql database qsqlite
    6
    0 Votes
    6 Posts
    1k Views
    Pablo J. RoginaP
    @Giggon said in SQLite database creation: Thread to be closed Please go and mark the post as solved. Thanks
  • Deserializing QSqlQuery using submethod in efficient way

    Unsolved C++ Gurus c++ qt mysql
    6
    0 Votes
    6 Posts
    1k Views
    SGaistS
    No it's not, you can see that with its constructors that take a QSqlDatabase parameter. No clear is not called, the destructor is. There's no need to create QSqlQuery objects on the heap.
  • 0 Votes
    8 Posts
    2k Views
    jsulmJ
    @projectbavaria Ging es nicht darum die gelesenen Daten in eine Datei reinzuschreiben? Wenn nicht, dann sollte auch nicht von einer Datei die Rede sein, da es sonst nur verwirrt. Also, was ist das: "haben wir versucht mit QFile aber es funktioniert nicht, Qt gibt meldung raus das es keine file gibt bzw. empty"? Wo wird in dem Code irgendwas mit QFile gemacht? Wie groß ist outByteArray und was ist drin?