当前位置: 代码迷 >> QT开发 >> 关于QSqlQuery的异常!
  详细解决方案

关于QSqlQuery的异常!

热度:542   发布时间:2016-04-25 02:58:57.0
关于QSqlQuery的错误!!
将从数据库中查询出来的记录,按照字段一个个的转换操作过程中。报了QMYSQLResult::cleanUp :unable to free statement handle的错误,紧着着在点击程序就崩溃了。因为每次调用函数中,使用局部的QSqlQuery对象,感觉没存在删除不删除的问题。怎么就报没有释放句柄的错误???
------解决思路----------------------
不知道是不是跟垃圾回收不及时有关。你的调用频率很高么?
------解决思路----------------------
不同的线程使用不同的QSqlDatabase对象(connection name 不一样)。
------解决思路----------------------
不同的线程不能共用一个QSqlDatabase对象!这个Qt的官方技术文档上有明确说明:
A connection can only be used from within the thread that created it. Moving connections between threads or creating queries from a different thread is not supported.

In addition, the third party libraries used by the QSqlDrivers can impose further restrictions on using the SQL Module in a multithreaded program. Consult the manual of your database client for more information

详细请看thread-support in Qt Modules