I have a great PyQt4 based Python program. In some places, it should be able to control the hardware for which the manufacturer provides the .net interface. I need to be able to load the appropriate library, if available, and ignore it otherwise.
If the library is missing, and I try to report this exception, then Qt reports an OLE initialization error, and all the drag and drop / copy / paste functions in my program fail.
Here is a minimal example:
import clr import sys from PyQt4 import QtGui import logging logger = logging.getLogger(__name__) try: clr.AddReference('foo')
This results in a Qt error:
Qt: Could not initialize OLE (error 80010106)
The program starts, but whenever I try to copy / paste, I get:
QClipboard::setMimeData: Failed to set data on clipboard ()
and drag-and-drop doesn't work at all.
If the library exists, the code works without problems. Interestingly, if I'm not trying to look at an exception (for example, replace the excluding block with "pass"), the code also works fine. Somehow, trying to see the exception, the .net interface will interfere.
Is there a better way to check if a library exists before trying to add it as a reference? Is there a way to connect reset.net before running QApplication to ensure that this kind of thing doesn't happen in the future? Any ideas why this issue is happening?