Results 1 to 7 of 7

Thread: Threading issue in DLL

  1. #1
    Join Date
    Jun 2012
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Threading issue in DLL

    Hi,

    I have a low level HW communication interface, which I would like to embed into a DLL.

    I create and starts a QThread, and in this tread's run loop, I create a simple handler object which I start with a QTimer:singleShot

    My problem:

    Everything works, as long I run the the Application from QtCreator (either in Debug or Release mode - both works)

    But when I build a static release version, the eventloop seems to stop or never start.

    I have build a very basic solution, for anyone to inspect.

    Please advice - Thanks
    Attached Files Attached Files

  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: Threading issue in DLL

    Static build will probably not allow you to load a dynamic library.
    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 2012
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Threading issue in DLL

    Hi,

    The DLL is loaded alright, I'm able to call functions getConst and getCounter in IBHandler, when it is loaded.

    But the mainloop in IBHandler is not running.

    Qt Code:
    1. #include "ibkernel.h"
    2.  
    3. IBKernel::IBKernel(QObject *parent) :
    4. QThread(parent)
    5. {
    6. }
    7.  
    8. IBKernel::~IBKernel()
    9. {
    10.  
    11. }
    12.  
    13. IBHandler* IBKernel::getHandler()
    14. {
    15. return handler;
    16. }
    17.  
    18. void IBKernel::startKernel()
    19. {
    20. exec();
    21. }
    22.  
    23. void IBKernel::stopKernel()
    24. {
    25. quit();
    26. }
    27.  
    28. void IBKernel::run()
    29. {
    30. handler = new IBHandler();
    31. //handler->moveToThread(this);
    32. QTimer::singleShot(10, handler, SLOT(MainLoop()));
    33.  
    34. exec();
    35.  
    36. delete handler;
    37. handler = 0;
    38. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "ibhandler.h"
    2.  
    3. IBHandler::IBHandler(QObject *parent) :
    4. QObject(parent)
    5. {
    6. mainLoopCnt = 30;
    7. }
    8.  
    9. IBHandler::~IBHandler()
    10. {
    11.  
    12. }
    13.  
    14. int IBHandler::getCounter()
    15. {
    16. return mainLoopCnt;
    17. }
    18.  
    19. int IBHandler::getConst()
    20. {
    21. return 99;
    22. }
    23.  
    24. void IBHandler::MainLoop()
    25. {
    26. // THIS STOPS or NEVER STARTS in the static released version
    27.  
    28. mainLoopCnt++;
    29.  
    30. QTimer::singleShot(0, this, SLOT(MainLoop()));
    31. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Threading issue in DLL

    have you statically built qt libraries as well?
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  5. #5
    Join Date
    Jun 2012
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Threading issue in DLL

    Hi,

    Yep! - All libs statically build. And used to build both the TestLibTest application and the DLL

  6. #6
    Join Date
    Jun 2012
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Threading issue in DLL

    Problem found!

    In standalone mode the DLL seems to need a QCoreApplication for the QTimer to work

    Thanks anyway

  7. #7
    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: Threading issue in DLL

    In any configuration QCoreApplication is needed for timers to work.
    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. Threading with rsh and rcp
    By jaxrpc in forum Newbie
    Replies: 2
    Last Post: 4th June 2010, 11:50
  2. Threading...?
    By sekatsim in forum Qt Programming
    Replies: 12
    Last Post: 10th June 2008, 01:14
  3. Qt Threading
    By avh in forum Newbie
    Replies: 7
    Last Post: 30th May 2008, 20:20
  4. Threading Issue
    By noufalk in forum Qt Programming
    Replies: 4
    Last Post: 4th August 2007, 13:45
  5. Sub-Threading
    By TheGrimace in forum Qt Programming
    Replies: 4
    Last Post: 7th June 2007, 16:38

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.