taynaron
taynaron

Reputation: 730

qWait analogue in PySide?

I've written a series of unit tests in PyQt using QTest and unittest. My code passes signals around, so to ensure that sufficient time has gone by after an operation before testing, I throw in some qWaits.

APP.ui.serverPortEdit.setText('1234')
QTest.mouseClick(APP.ui.userConnectButton, Qt.LeftButton)
QTest.qWait(2000) #wait for the server to connect
self.checkOnline()

I'd like to run the same tests in PySide, but I can find no analogue to qWait. Have I overlooked something? The PySide qTest docs make no mention of it.

Upvotes: 5

Views: 1535

Answers (2)

Onlyjus
Onlyjus

Reputation: 6159

For others that come across this (my first Google hit) time.sleep() does not process QEvents. I came across this PyQt4/PySide wrapper that defines qWait to use with PySide:

from datetime import datetime as datetime_, timedelta

@staticmethod
def qWait(t):
    end = datetime_.now() + timedelta(milliseconds=t)
    while datetime_.now() < end:
        QtGui.QApplication.processEvents()
QtTest.QTest.qWait = qWait

Upvotes: 3

AlexVhr
AlexVhr

Reputation: 2074

Can't you use python's time.sleep()?

Upvotes: 2

Related Questions