I have a Windows / Linux Qt 4.3 application that uses drag and drop in QTreeView. I have two very similar applications that use the same set of Qt libraries. Drag and Drop works on both Linux and Windows.
In an application that does not work, the QDrag object is deleted as soon as the mouse moves. It is removed by the DeferredDelete event from the event queue, which is still being processed in Qt during drag and drop. I do not know how to see why the QDrag object is being deleted prematurely.
I cannot find a good way to debug this problem. I have compared the source and cannot find anything obvious. I tried to use the code from one of the applications in another application.
Any suggestions?
Update:
The reason the QDrag operation failed is because COM was not initialized successfully, so the call to DoDragDrop in QDrag :: exec returned immediately. QApplication tried to initialize COM by calling OleInitialize in qt_init, but with the error "Unable to change the flow mode after installing it."
Interestingly, this happens even when OleInitialize is the first, which is done mainly, so the flow mode is first set by some external dependency. One of the differences between applications running on Windows is that the one that doesnβt work also contains .NET code, perhaps this is a problem.
It is decided:
This issue is a COM / CLR interoperability issue. The CLR sets the state of the apartment in the MTA when it is initialized, and then when Qt tries to initialize COM, it fails. This problem and old solution are discussed by Adam Nathan in Gotcha with STAThreadAttribute and managed by C ++ . In Visual Studio 2005, you can set the / CLRTHREADATTRIBUTE: STA compiler option in Configuration Properties> Linker> Advanced to set the Threading attribute to STA without creating a new entry point.
source share