Results 1 to 12 of 12

Thread: GUI application as DLL. Repaint is blocked.

  1. #1
    Join Date
    Jun 2011
    Posts
    13
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default GUI application as DLL. Repaint is blocked.

    Hello!
    I have Qt4 GUI project. It`s implemented as DLL. The main application which uses my DLL calling interface functions from MainThread. Here is the message loop of main application:
    Qt Code:
    1. while(buckets_rendered<numRects && events!=0)
    2. {
    3. while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
    4. {
    5. TranslateMessage(&msg);
    6. DispatchMessage(&msg);
    7. }
    8.  
    9. stat = MsgWaitForMultipleObjects(numHandles, handles, FALSE, INFINITE, QS_ALLINPUT);
    10. if(stat == (WAIT_OBJECT_0 + numHandles))
    11. {
    12. continue;
    13. }
    14. else // message comes from the events
    15. {
    16. id = stat - WAIT_OBJECT_0;
    17. --events;
    18.  
    19. // ...
    20. }
    21. }
    To copy to clipboard, switch view to plain text mode 

    All works fine with Qt 4.7.3, but when we use Qt 4.5.3 my DLL is ‘blocked’! When I click some button in my GUI app, nothing happens. But when next I click right mouse button some events occure and I see an effect from the first left mouse button click and an effect from right button click…Why only right mouse button click force repaint? I`m confused…

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

    Default Re: GUI application as DLL. Repaint is blocked.

    Where do you process Qt's events?
    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
    Jun 2011
    Posts
    13
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: GUI application as DLL. Repaint is blocked.

    Quote Originally Posted by wysota View Post
    Where do you process Qt's events?
    I really don`t do any special managment for events. I just have this code for MyApplication class (inherited from QApplication):
    Qt Code:
    1. bool MyApplication::notify(QObject * obj, QEvent * event) {
    2. try {
    3. return QApplication::notify(obj, event);
    4. }
    5. catch(std::exception & ex) {
    6. handleError(ex.what());
    7. }
    8. catch(...) {
    9. handleError(tr("Critical error: unhandled exception"));
    10. }
    11. return false;
    12. }
    To copy to clipboard, switch view to plain text mode 




    Added after 13 minutes:


    Maybe it`ll be useful if I show you a code of creating and using MyApplication object.
    Main dll function is:
    Qt Code:
    1. BOOL APIENTRY DllMain(HANDLE hinstDLL, DWORD ul_reason_for_call, LPVOID lpReserved)
    2. {
    3. BOOL ret = TRUE;
    4.  
    5. switch(ul_reason_for_call)
    6. {
    7. case DLL_PROCESS_ATTACH:
    8. {
    9. qInstallMsgHandler(myMessageHandler);
    10. }
    11. break;
    12.  
    13. case DLL_THREAD_ATTACH:
    14. break;
    15.  
    16. case DLL_THREAD_DETACH:
    17. break;
    18.  
    19. case DLL_PROCESS_DETACH:
    20. {
    21. fBitmapManager *bmmManager = fr_get_bitmap_mgr();
    22. if(bmmManager)
    23. bmmManager->DeleteAllVFBs("defaultvfb");
    24. }
    25. break;
    26. }
    27.  
    28. return ret;
    29. }
    To copy to clipboard, switch view to plain text mode 

    As you see, nothing special...

    There is interface functions for my dll:
    Qt Code:
    1. bool RegisterPlugins(fPluginManager *plugMgr)
    2. {
    3. plugMgr->RegisterPlugin("vfb", "defaultvfb", VFBPluginModel::getInstance,0,0);
    4. return TRUE;
    5. }
    6.  
    7. bool UnRegisterPlugins(fPluginManager *plugMgr)
    8. {
    9. plugMgr->UnRegisterPlugin("vfb", "defaultvfb");
    10. return TRUE;
    11. }
    12.  
    13. extern "C" fplug_export fBool initializePlugins(fPluginManager *plugMgr)
    14. {
    15. return RegisterPlugins(plugMgr);
    16. }
    17.  
    18. extern "C" fplug_export fBool uninitializePlugins(fPluginManager *plugMgr)
    19. {
    20. return UnRegisterPlugins(plugMgr);
    21. }
    To copy to clipboard, switch view to plain text mode 

    We interested in VFBPluginModel::getInstance code. This is a singletone wich creates an QApplication object.
    Class definition:
    Qt Code:
    1. class VFBPluginModel : public QObject
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6.  
    7. VFBPluginModel();
    8. virtual ~VFBPluginModel();
    9.  
    10. static void *getInstance();
    11.  
    12. ...
    13.  
    14.  
    15. private:
    16. VFBApplication a;
    17. };
    To copy to clipboard, switch view to plain text mode 

    And creating:
    Qt Code:
    1. VFBPluginModel::VFBPluginModel() : a(i, &name, this)
    2. {
    3.  
    4. }
    To copy to clipboard, switch view to plain text mode 

    Code for VFBApplication class:
    Qt Code:
    1. class VFBApplication: public QApplication {
    2. Q_OBJECT
    3.  
    4. public:
    5. VFBApplication(int & argc, char ** argv, VFBPluginModel* plugin);
    6. virtual ~VFBApplication();
    7.  
    8. virtual bool notify(QObject * obj, QEvent * event);
    9.  
    10. ...
    11. };
    12.  
    13.  
    14. VFBApplication::VFBApplication(int & argc, char ** argv, VFBPluginModel* plugin): QApplication(argc, argv) mainWnd_(NULL)
    15. {
    16. mainWnd_ = new MainWindow(appModel_);
    17. mainWnd_->show();
    18. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Grinchman; 6th June 2011 at 10:35.

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

    Default Re: GUI application as DLL. Repaint is blocked.

    So if you don't process Qt events from within your non-Qt app, then how do you expect them to be handled? Do you have a call to QCoreApplication::exec() or QCoreApplication::processEvents() anywhere?
    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
    Jun 2011
    Posts
    13
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: GUI application as DLL. Repaint is blocked.

    No, I don`t use it. I little bit confused about using exec() in dll.
    But, anyway....my application works fine in Qt 4.7.3...what fundamental difference between 4.7.3 and 4.5.3? (

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

    Default Re: GUI application as DLL. Repaint is blocked.

    Make sure it indeed works fine in Qt 4.7.3 because there is no way for it to work fine if you don't process Qt's events.
    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.


  7. #7
    Join Date
    Jun 2011
    Posts
    13
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: GUI application as DLL. Repaint is blocked.

    Just tested. It works fine in Qt 4.7.3...
    My dll originally was a standalone GUI app, and it had main function with app.exec() call. When it migrated into dll I just replaced main function by showed above DLLMain function (without app.exec() call) with several dll_export functions....

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

    Default Re: GUI application as DLL. Repaint is blocked.

    Does your notify() implementation ever get called? Place a debug statement there and find out. Print the object name and event type from the arguments the method receives.
    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.


  9. #9
    Join Date
    Jun 2011
    Posts
    13
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: GUI application as DLL. Repaint is blocked.

    Yeah, it`s always called. And sequences of events are quite common: ApplicationActivate....MouseButtonClicked and so on...And objects are ordinary: QApplication object, MainWindow object, internal widgets, buttons and etc...

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

    Default Re: GUI application as DLL. Repaint is blocked.

    Quote Originally Posted by Grinchman View Post
    Yeah, it`s always called.
    In both 4.5 and 4.7?

    And sequences of events are quite common: ApplicationActivate....MouseButtonClicked and so on...And objects are ordinary: QApplication object, MainWindow object, internal widgets, buttons and etc...
    Please grep your code for calls to QApplication and QCoreApplication classes and paste them here.
    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.


  11. The following user says thank you to wysota for this useful post:

    Grinchman (8th June 2011)

  12. #11
    Join Date
    Jun 2011
    Posts
    13
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: GUI application as DLL. Repaint is blocked.

    wysota, your tip about processEvent was really helpful. Now non-Qt application is forcing my object QApplication to process events when it gets some windows message and it works! ) So, we may conclude that Qt 4.7 is somehow forcing processEvent without exec() and manualy call of processEvent()...

    So, thank you so much for your time and help!

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

    Default Re: GUI application as DLL. Repaint is blocked.

    No, it is not forcing processEvents().
    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.


Similar Threads

  1. Replies: 4
    Last Post: 17th October 2010, 22:30
  2. GUI blocked
    By Astrologer in forum Qwt
    Replies: 1
    Last Post: 24th June 2010, 14:07
  3. how blocked center in QGraphicsScene
    By estel in forum Newbie
    Replies: 3
    Last Post: 20th March 2010, 10:11
  4. GUI thread blocked using QThread.
    By summer_of_69 in forum Qt Programming
    Replies: 11
    Last Post: 18th May 2009, 09:43
  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
  •  
Qt is a trademark of The Qt Company.