New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Qt error when integrate pyqt4 and pywinauto #472
Comments
Hi @chenhuaizhen can you try |
@vasily-v-ryabov Yes, it works, many thanks for your help! |
OK, it seems we should move COM initialization from import code to another place (when creating |
By the way We have one serious crash fixed in 0.6.4. So I would recommend the second solution. |
@vasily-v-ryabov I have tried your new method with pywinauto==0.6.4, but got another warning, my code is: from PyQt4 import QtGui
import sys
sys.coinit_flags = 2
import pywinauto
def main():
app = QtGui.QApplication(sys.argv)
w = QtGui.QWidget()
w.resize(250, 150)
w.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main() and the warning is:
|
This is just a warning and it looks reasonable. But just to make an experiment... Can you call app = QtGui.QApplication(sys.argv)
import pywinauto Is there some warnings? |
@vasily-v-ryabov Sure, and my code is: import sys
from PyQt4 import QtGui
def main():
app = QtGui.QApplication(sys.argv)
import pywinauto
w = QtGui.QWidget()
w.resize(250, 150)
w.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main() and I got a warning:
And I have a question about the "sys.coinit_flags", although the warning looks reasonable, can I hide that warning when I run my program? |
Try this code before import warnings
warnings.simplefilter("ignore", UserWarning) Taken from here: https://stackoverflow.com/q/11175388/3648361 |
@vasily-v-ryabov Many thanks, it works |
Well, I decided to re-qualify this thread as a question, because it's impossible to predict whether MTA or STA mode will be chosen by next import or statement. Let's leave MTA a default mode. Closing. |
Sorry, but what happened to this issue? Last year I used the hide warning fix you provided and left a comment in my code reminding me the extra lines were there temporarily till pywinauto 0.6.6. release. It's been over a couple of months now and we've moved to the latest pywinauto version. But when I remove the temporary lines I still see the "pywinauto QWindowsContext: OleInitialize() failed: COM error..." warning is there. Will there be a permanent fix for this in the future? |
The latest comment in the thread should explain our decision. If we switch to STA as a default mode, it can break another library that wants to use MTA. And vice versa. So permanent fix for all cases is impossible. Just import pywinauto later because it can adjust to COM threading mode already used by Qt4. While Qt4 can't do the same thing for pywinauto. Removing the warning completely is also impossible, because this message is important at least first time. Just disable the warning if you don't want to see it. It's standard way Python provides. It can hide other Also the most important use cases involve interacting with another process, not with its own Python app. So we'd better concentrate on new features like UI recorder and Linux backend. Thanks for understanding. |
Environment
Detail
Hello all, I have a problem when integrate pyqt4 and pywinauto, the code like below:
And I get the error:
If I remove "import pywinauto" and it can run normally.
thanks.
The text was updated successfully, but these errors were encountered: