]> Some of my projects - localmylist.git/commitdiff
Check if workThread exists before trying to access it.
authorAPTX <marek321@gmail.com>
Sat, 15 Mar 2014 13:22:48 +0000 (14:22 +0100)
committerAPTX <marek321@gmail.com>
Sat, 15 Mar 2014 13:22:48 +0000 (14:22 +0100)
This can only happen if workThread wasn't created and you're trying to
get a Database from a wrong thread.

localmylist/mylist.cpp

index 39cfc705053e3b0b9997e51dcd75e7a20b018c62..a1f616d839f361fa5b5c63796dd8c007b471497c 100644 (file)
@@ -88,8 +88,14 @@ Database *MyList::database() const
        if (QThread::currentThread() == thread())
                return db;
        // QThread is in the thread that created it.
-       if (QThread::currentThread() == workThread->database()->thread())
+       if (workThread && QThread::currentThread() == workThread->database()->thread())
                return workThread->database();
+
+       qWarning("Tried to get a database from a different thread. Qt database "
+                        "plugins are not thread-safe. This extends to the LML Database. "
+                        "You can only use a Database from the thread in which MyList was "
+                        "created.");
+
        return 0;
 }