Results 1 to 2 of 2

Thread: QtWinMigrate and QThread event loop

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

    Default QtWinMigrate and QThread event loop

    I've recently discovered that if an application creates a new background QThread and calls QThread::start() to start the thread's event loop, that thread will sometimes process QMfcApp::winEventFilter, which in turn will cause MFC events to be processed in the background thread. However, this will cause some problems because the MFC events are only meant to be processed in the application's main thread.

    Can anyone confirm if it will be ok to do a thread check inside QMfcApp::winEventFilter and only allow it to proceed if the current thread is the main thread? I'm not familiar with the lineage of this class, but the way it's written, I think there was an assumption that it would only get called from the main thread.

    Thanks,

    Doug

  2. #2
    Join Date
    Aug 2013
    Posts
    1
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QtWinMigrate and QThread event loop

    I would like to know a proper solution to this as well. In my case calling QNetworkAccessManager::get() puts main thread into QWaitCondition::wait() mode and QCoreApplication::winEventFilter() starts to get called from a worker QThread until QNAP::get() finishes it's task. That immediately crashes the application as MFC per-thread objects become inaccessible.
    Bellow is my temporary solution, although it kinda defeats the whole point of multithreading as it becomes the same as doing network request on the main thread. Anyone is aware of a better alternative?
    Qt Code:
    1. bool QMfcApp::winEventFilter(MSG *msg, long *result)
    2. {
    3. if (QThread::currentThread() != QApplication::instance()->thread())
    4. return false;
    5.  
    6. ...
    7. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 25
    Last Post: 28th October 2011, 20:22
  2. Replies: 1
    Last Post: 22nd July 2010, 09:16
  3. Terminate a QThread with an event loop
    By paolom in forum Qt Programming
    Replies: 2
    Last Post: 12th May 2010, 11:53
  4. QThread event loop blocking the GUI
    By JoeMerchant in forum Qt Programming
    Replies: 4
    Last Post: 18th July 2009, 07:54
  5. QThread event loop seems blocked
    By eurodatar in forum Qt Programming
    Replies: 3
    Last Post: 6th May 2009, 16:50

Tags for this Thread

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.