Reputation: 249
I have an QOGLWidget widget which is constructed in a another window, which is activated by button from the QMainwindow. I'm trying to send a surface of an image from the widget to the main window's QOGLWidget, the problem that it crashes and gives a first chance exception access violation.
Upvotes: 2
Views: 267
Reputation: 19112
There are three things that I think may be going on in this situation:
Your connection between your frame generator and the GUI (SimulatorWindow + GLSimulatorWidget) are connected by Qt::AutoConnection and ends up turning into a Qt::DirectConnection when they reside on separate threads. Specify a connection of Qt::QueuedConnection to overcome this problem (if indeed they are on separate threads).
You could be handling QPixmaps off of the GUI thread. This usually will print out a warning, but maybe still function. In general if your processing an image not in the GUI thread, and then sending it to the GUI thread, you need to use something besides QPixmap, like QImage.
Your frame object may be going out of scope by the time it gets to your GUI. For example, if you build a frame, and store it in a local scope on the stack, and you pass it into a handler or a container...
...then when you leave the local scope to representing the object in the GUI, your frame object will be gone and your handler/container is left holding a bad pointer.
To fix this, initialize onto the heap and stick to the Qt Object Model. Also I like to make my containers on the heap also as member variables to the class they belong to.
So in summary: Check your connection types and if your frame generator is on the GUI thread or not, use QImage not QPixmap if you are in a thread that is not the GUI, and make sure your pointers are not going out of scope.
Upvotes: 1