QT线程。使用pyqt设置QtHelpEngine

时间:2016-07-16 04:47:12

标签: python qt pyqt

我很感激使用QtHelpEngine提供了一些帮助。我尝试了几种方法,各种结果。下面是对我来说最直观的代码,但我遇到了线程问题。我现在遇到的问题是使用QT信号以正确的顺序执行必要的操作。

我得到的错误是:

  

QObject:无法为不同的父级创建子级   线。 (Parent是QHelpEngine(0x226f6143780),父亲的主题是   QmlSearch(0x226f61382a0),当前线程为QThread(0x226f61bda80)

如果有人能就如何解决这个问题或如何使用帮助引擎给我一些建议,我将不胜感激。

谢谢!

from PyQt5 import QtHelp, QtCore
import sys
import time


class QmlSearch(QtCore.QThread):

    def run(self):
        # setup help engine
        qhcPath = 'C:/Users/jonoa/Documents/TEST.qhc'   # just a temporary test file
        self.qmlHelp = QtHelp.QHelpEngine(qhcPath)
        self.qmlHelp.setupFinished.connect(self.onSetupFinished)
        self.qmlHelp.setupData()

    def onSetupFinished(self):
        print('setup finished')
        # when setup is finished register documentation
        path2 = 'C:/Program Files/QT/Docs/Qt-5.7/qtquick.qch'   # an example test file
        self.qmlHelp.registerDocumentation(path2)

        # Then setup the search engine
        self.qmlSearch = self.qmlHelp.searchEngine()    # This is where the script breaks.
        self.qmlSearch.reindexDocumentation()

    def onIndexFinished(self):
        print('indexing finished')
        # create search query and perform search
        query = QtHelp.QHelpSearchQuery(0, ['rectangle'])
        self.qmlSearch.searchingFinished.connect(self.onSearchFinished)
        self.qmlSearch.search([query])

    def onSearchFinished(self):
        print('search finished')

        # print some of the hits and finish
        print([a for a in self.qmlSearch.hits(0, self.qmlSearch.hitCount()) if 'rectangle' in a[1].lower()])
        self.finished.emit()

if __name__ == '__main__':
    app = QtCore.QCoreApplication(sys.argv)
    thread = QmlSearch()
    thread.finished.connect(app.exit)
    thread.start()
    sys.exit(app.exec_())

0 个答案:

没有答案