我有一个QThread
,它监视数据库的内容,如果发生了更改,它将更新应用程序中的信息,并提供一个功能,该功能可以在需要更改时浏览其他数据库,这就是我看到的之所以出现问题,是因为如果仍然有一些使用该数据库的已卸载模块,则它会停止信息更新和其他模块的加载,因为当QFileDialog
直接位于它使用的数据库的文件夹/路径中时,它无法访问该数据库
我使用了try
块并且可以工作,但是如果它确实需要访问数据库,它仍然不允许我的应用继续加载其他模块。
我尝试使用另一个应用程序的QFileDialog
访问数据库的路径,看来我有问题的应用程序仍然可以访问。
这是一个小例子。
import sys, time, sqlite3
from PyQt4.QtCore import QThread
from PyQt4.QtGui import QApplication, QMainWindow, QFileDialog
class testThread(QThread):
def __init__(self, parent=None):
QThread.__init__(self, parent)
self.parent = parent
def run(self):
while True:
conn = None
while conn is None:
try:
conn = sqlite3.connect("path\\of\\db", 10.0)
except Exception:
import traceback
traceback.print_exc()
time.sleep(1.0)
time.sleep(1.0)
class testMain(QMainWindow):
def __init__(self, parent=None):
super(testMain, self).__init__(parent)
testThread_obj = testThread(self)
testThread_obj.start()
new_path = unicode(QFileDialog.getOpenFileName(None, 'Select Database', "path\\of\\db", "(*.db)")).replace("/", "\\")
def run():
app = QApplication(sys.argv)
GUI = testMain()
sys.exit(app.exec_())
run()
即使QThread
在当前数据库的路径中,有没有办法允许QFileDialog
访问数据库?或这就是它的工作方式,因为我在文档中看不到任何内容。