Qt-interest Archive, March 2008
Re: [Linux] Possible Qt/MySQL threading bug
Message 1 in thread
Same thing happens to me!!
Very annoying. Sems to be related to calling
QSqlDatabase::addDatabase() from a thread that is not the main thread.
On Thu, Dec 13, 2007 at 5:59 AM, Stephen Collyer
<scollyer@xxxxxxxxxxxxxxxx> wrote:
> I'm seeing the following message emitted from somewhere
> in the Qt MySQL driver when a thread terminates. The
> thread has, during its lifetime, opened a MySQL db
> connection:
>
> "Error in my_thread_global_end(): 1 threads didn't exit"
>
> This is generated consistently, on every execution of
> the program.
>
> I'm using MySQL 5.0.45 and qt-x11-opensource-src-4.3.2
> (that's the latest MySQL, AFAIK).
>
> Google suggests that this problem is not confined to
> Qt, but it's not clear to me whether or not it's due
> to Qt failing to close down correctly on thread termination,
> or if it's a bug that's arisen in MySQL itself.
>
> Anyone know anything about this ?
>
> --
> Regards
>
> Steve Collyer
> Netspinner Ltd
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
--
[ signature omitted ]
Message 2 in thread
Hi,
Ð ÐÐÐ, 03/03/2008 Ð 09:47 -0800, Alan Ezust ÐÐÑÐÑ:
> Same thing happens to me!!
> Very annoying. Sems to be related to calling
> QSqlDatabase::addDatabase() from a thread that is not the main thread.
Yes, you forgot to remove a database.
Try running QSqlDatabase::removeDatabase("NAME") from your thread.
--
[ signature omitted ]
Message 3 in thread
On Mon, Mar 3, 2008 at 1:25 PM, Nikolay Derkach <nderkach@xxxxxxxxx> wrote:
> Hi,
>
> В Пнд, 03/03/2008 в 09:47 -0800, Alan Ezust пишет:
>
> > Same thing happens to me!!
> > Very annoying. Sems to be related to calling
> > QSqlDatabase::addDatabase() from a thread that is not the main thread.
>
> Yes, you forgot to remove a database.
> Try running QSqlDatabase::removeDatabase("NAME") from your thread.
Yes, but in the case of Qt4 + libmysql5, even after calling close() or
removeDatabase(), I still get an extra thread running that won't die.
Im sure that with other database drivers, that's how it works.
N▀╖╡ФЛr╦⌡zг╖u╘ ┼[h╙ь╖╣Йч╡зч╙Г╛╤зХ√[^r(⌡╜├ИЛ╧╩╝&ч┼{azк⌡█Г-╒╩ay╨х╦╛╣╙э├+чjwb²З+≥╚b╒xm╤÷Ъ√+-╡зХ√[^r(⌡З╜┼{^╜К-
Message 4 in thread
04.03.08, Alan Ezust <alan.ezust@xxxxxxxxx> написал(а):
>
> On Mon, Mar 3, 2008 at 1:25 PM, Nikolay Derkach <nderkach@xxxxxxxxx>
> wrote:
> > Hi,
> >
> > В Пнд, 03/03/2008 в 09:47 -0800, Alan Ezust пишет:
> >
> > > Same thing happens to me!!
> > > Very annoying. Sems to be related to calling
> > > QSqlDatabase::addDatabase() from a thread that is not the main
> thread.
> >
> > Yes, you forgot to remove a database.
> > Try running QSqlDatabase::removeDatabase("NAME") from your thread.
>
>
> Yes, but in the case of Qt4 + libmysql5, even after calling close() or
> removeDatabase(), I still get an extra thread running that won't die.
> Im sure that with other database drivers, that's how it works.
>
Do you actually call remove removeDatabase() from your thread (not the main
one)?
Just to mention, once I spent a bulk of time struggling with this error. The
solution was to call removeDatabase() from my new thread. Maybe I did it way
too hacky, so if anyone has a better solution I'll be glad to see it. Here
is a snippet of my code corresponding to mysql connection running in a
thread:
---
DBThread::DBThread(QObject *parent)
: QThread(parent)
{
stopped = true;
}
DBThread::~DBThread()
{
if (!stopped) DBThread::stop();
wait(1); // wait for thread to stop
}
void DBThread::run()
{
<snip>
forever
{
if (stopped)
{
stopThread();
return;
}
}
}
bool DBThread::createConnection()
{
/* try to open database */
extern QString host;
extern QString dbname;
extern QString user;
extern QString passwd;
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL", "IRK");
db.setHostName(host);
db.setDatabaseName(dbname);
db.setUserName(user);
db.setPassword(passwd);
if (!db.open())
{
qDebug() << db.lastError();
return false;
}
return true;
}
void DBThread::trigger(bool trigger)
{
if (trigger) start();
else stop();
}
void DBThread::stop()
{
// qDebug() << "stopped";
emit connected(false);
stopped = true;
}
void DBThread::stopThread()
{
QMutexLocker locker(&mutex);
QSqlDatabase::removeDatabase("IRK");
timer.stop();
emit updateValue("");
}
--
[ signature omitted ]