WindowsContext: OleInitialize() failed: "COM error 0x80010106 RPC_E_CHANGED_MODE (Unknown error 0x0ffffffff80010106)"

4

I'm programming in python 3.4.4 (32 bits), in windows 8. I'm running an app with PyQt5, the app was working well, but since i installed pywinauto 0.6.4 to set the focus on other app with:

other_app = pywinauto.Application().connect(process=int(code))
other_app.top_window().set_focus()

if i run My_app = QApplication(sys.argv), in console appears the next warning message, with no other information:

QWindowsContext: OleInitialize() failed:  "COM error 0x80010106 RPC_E_CHANGED_MODE (Unknown error 0x0ffffffff80010106)"
SetProcessDpiAwareness failed: "COM error 0x80070005  (Unknown error 0x0ffffffff80070005)"

I suspect that's because there is a conflict between the pywinauto and the PyQt5.QtWidgets.QApplication modules. After the "warning" the program runs good, but i still don't now how to fix it.

This is the Minimal, Complete, and Verifiable example:

from PyQt5.QtWidgets import QApplication
import pywinauto
import sys


def main():
    app = QApplication(sys.argv)
    app.exec_()


if __name__ == '__main__':
    main()
python
pyqt5
pywinauto
asked on Stack Overflow Jul 11, 2018 by JoakoLowRider • edited Jul 11, 2018 by JoakoLowRider

2 Answers

6

According to this post a workaround is to use sys.coinit_flags = 2 and warning module.

import sys
import warnings
warnings.simplefilter("ignore", UserWarning)
sys.coinit_flags = 2
import pywinauto
from PyQt5.QtWidgets import QApplication, QMainWindow


def main():
    app = QApplication(sys.argv)
    w = QMainWindow()
    w.show()
    app.exec_()


if __name__ == '__main__':
    main()
answered on Stack Overflow Jul 11, 2018 by eyllanesc
0

Try to import in this way:

from PyQt5 import QtWidgets
...
app = QtWidgets.QApplication(sys.argv)
w = QMainWindow()
w.show()
app.exec_()

This works for me.


User contributions licensed under CC BY-SA 3.0