PDA

View Full Version : Interrupt in Qt Event



Lisi
28th October 2012, 22:35
I am working with Qt, Directx 11 and C++. When my widget opens I start an Engine with system->Run(). This function calls every frame a function named Frame() as long as the variable done is set to false.

When the closing event is called in my Qt class, then I want to shutdown the engine. So I made a function named isDone() which sets the variable done to false and then I release all variables I have created with System->Shutdown(). But the problem is that the program crashes because when the closing event is called, the System->Run() function is interrupted as long as the closing event is over, but I want that the Run() function is executed after the call from the function isDone() before the System->Shutdown() function is executed.

Is there any possibility to make an interrupt in the closing event, so that other things in the queue are executed?

wysota
29th October 2012, 07:31
Show us some code.

Lisi
29th October 2012, 10:08
ok: this is my closing event for my main widget
void qtTest::closeEvent( QCloseEvent *event )
{
SystemClass* sys = m_widget->closeWindow();
sys->setDone();
sys->Shutdown();
delete sys;
sys = 0;
}
and this is my sys-> Run() function which is an endless loop which only stops if the done variable is set to true, which I do with my setDone() function:

void SystemClass::Run()
{
MSG msg;
bool result;


// Initialize the message structure.
ZeroMemory(&msg, sizeof(MSG));

// Loop until there is a quit message from the window or the user.
//done = false;
while(!done)
{
// Handle the windows messages.
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

// If windows signals to end the application then exit out.
if(msg.message == WM_QUIT)
{
done = true;
}
else
{
// Otherwise do the frame processing.
result = Frame();
if(!result)
{
done = true;
}
}



}

return;
}

The problem is that the Run function doesn't end because it is interrupted by the closing event. Do you know what I mean?

wysota
29th October 2012, 10:29
And how is this related to Qt? The only thing involving Qt is that you have some code placed in closeEvent(). I don't even know how the close event is supposed to be delivered since you're not letting Qt process any events when you're stuck in the while loop. Or are you using threads?

Lesiok
29th October 2012, 10:32
First of all variable done should be protected by mutex