Results 1 to 5 of 5

Thread: Interrupt in Qt Event

  1. #1
    Join Date
    Oct 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Interrupt in Qt Event

    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?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Interrupt in Qt Event

    Show us some code.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Oct 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Interrupt in Qt Event

    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?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Interrupt in Qt Event

    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?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Interrupt in Qt Event

    First of all variable done should be protected by mutex

Similar Threads

  1. How to interrupt QScriptValu::call()
    By QtIsCute in forum Newbie
    Replies: 9
    Last Post: 21st July 2012, 13:05
  2. Replies: 2
    Last Post: 7th June 2011, 09:24
  3. Sending OS I/O interrupt signals!
    By nofortee in forum Qt Programming
    Replies: 6
    Last Post: 13th July 2010, 16:42
  4. Interrupt/Exception caught while compiling Qt program
    By Qt Coder in forum Qt Programming
    Replies: 1
    Last Post: 25th June 2010, 23:08
  5. Control-C to interrupt is not working
    By rburge in forum Qt Programming
    Replies: 1
    Last Post: 17th April 2006, 22:18

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.