PDA

View Full Version : Threading issue in DLL



CristonDK
14th June 2012, 13:13
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

wysota
14th June 2012, 15:26
Static build will probably not allow you to load a dynamic library.

CristonDK
14th June 2012, 15:45
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.


#include "ibkernel.h"

IBKernel::IBKernel(QObject *parent) :
QThread(parent)
{
}

IBKernel::~IBKernel()
{

}

IBHandler* IBKernel::getHandler()
{
return handler;
}

void IBKernel::startKernel()
{
exec();
}

void IBKernel::stopKernel()
{
quit();
}

void IBKernel::run()
{
handler = new IBHandler();
//handler->moveToThread(this);
QTimer::singleShot(10, handler, SLOT(MainLoop()));

exec();

delete handler;
handler = 0;
}



#include "ibhandler.h"

IBHandler::IBHandler(QObject *parent) :
QObject(parent)
{
mainLoopCnt = 30;
}

IBHandler::~IBHandler()
{

}

int IBHandler::getCounter()
{
return mainLoopCnt;
}

int IBHandler::getConst()
{
return 99;
}

void IBHandler::MainLoop()
{
// THIS STOPS or NEVER STARTS in the static released version

mainLoopCnt++;

QTimer::singleShot(0, this, SLOT(MainLoop()));
}

amleto
14th June 2012, 18:20
have you statically built qt libraries as well?

CristonDK
14th June 2012, 20:51
Hi,

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

CristonDK
15th June 2012, 18:04
Problem found!

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

Thanks anyway

wysota
15th June 2012, 18:07
In any configuration QCoreApplication is needed for timers to work.