Ok..
here is what I have now.
What works:
a) The plugNPlay object has timers and connects that work.
b) connect(plugNPlay, SIGNAL(JustConnected(bool)),this,SLOT(initialize(b ool)), Qt::QueuedConnection); is also working
c) connect(retryTmr,SIGNAL(timeout()), this, SLOT(handleNoResponse())); also works.
What doesn't work:
a) In the initialize(bool) slot.. I have retryTmr->start();... the system complains that:
QObject::killTimer: timers cannot be stopped from another thread
QObject::startTimer: timers cannot be started from another thread
1) First MySystemWrapper which is called first. I had to put the MySystem object in another thread because if I don't.. nothing works!
bool MYSYSTEMWRAPPERSHARED_EXPORT connect(){
mMySystem = new MySystem();
mMySystem->moveToThread(thread2);
thread2->start();
QMetaObject::invokeMethod(mMySystem,
"run", Qt
::QueuedConnection);
return true;
}
bool MYSYSTEMWRAPPERSHARED_EXPORT connect(){
mMySystem = new MySystem();
mMySystem->moveToThread(thread2);
thread2->start();
QMetaObject::invokeMethod(mMySystem, "run", Qt::QueuedConnection);
return true;
}
To copy to clipboard, switch view to plain text mode
2) Then, the MySystem class is called from the above. The constructor is only to start the QApp. With the signal that will call exec().... ONLY then I call the run() that will created my program objects.
MySystem
::MySystem(QObject *parent
) :{
if (QAppPriv::pThread == NULL)
{
qDebug()<< "QAppPriv::pThread created";
// Separate thread for application thread
// Direct connection is mandatory
QObject::connect(QAppPriv
::pThread,
SIGNAL(started
()),
this,
SLOT(OnExec
()), Qt
::DirectConnection);
QAppPriv::pThread->start();
}
}
void MySystem::OnExec(){
{
qDebug()<< "QAppPriv::pApp created";
QAppPriv::pApp->exec();
if (QAppPriv::pApp)
delete QAppPriv::pApp;
}
}
void MySystem::run(){
plugNPlay = new HID_PnP();
plugNPlay->moveToThread(thread);
isConnected = false;
retryTmr->setSingleShot(true);
retryTmr->setInterval(10); //10ms between retry
connect(retryTmr,SIGNAL(timeout()), this, SLOT(handleNoResponse()));
connect(plugNPlay, SIGNAL(JustConnected(bool)),this,SLOT(initialize(bool)),
Qt::QueuedConnection);
}
MySystem::MySystem(QObject *parent) :
QObject(parent)
{
if (QAppPriv::pThread == NULL)
{
qDebug()<< "QAppPriv::pThread created";
// Separate thread for application thread
QAppPriv::pThread = new QThread();
// Direct connection is mandatory
QObject::connect(QAppPriv::pThread, SIGNAL(started()), this, SLOT(OnExec()), Qt::DirectConnection);
QAppPriv::pThread->start();
}
}
void MySystem::OnExec(){
if (QCoreApplication::instance() == NULL)
{
qDebug()<< "QAppPriv::pApp created";
QAppPriv::pApp = new QCoreApplication(QAppPriv::argc, QAppPriv::argv);
QAppPriv::pApp->exec();
if (QAppPriv::pApp)
delete QAppPriv::pApp;
}
}
void MySystem::run(){
QThread *thread = new QThread;
plugNPlay = new HID_PnP();
plugNPlay->moveToThread(thread);
isConnected = false;
retryTmr = new QTimer(this);
retryTmr->setSingleShot(true);
retryTmr->setInterval(10); //10ms between retry
connect(retryTmr,SIGNAL(timeout()), this, SLOT(handleNoResponse()));
connect(plugNPlay, SIGNAL(JustConnected(bool)),this,SLOT(initialize(bool)),
Qt::QueuedConnection);
}
To copy to clipboard, switch view to plain text mode
Bookmarks