Hi All,

I am working on BB10 native extension which is written in QT. I have started a thread to execute my network request.

Qt Code:
  1. void* SignalThread(void* parent) {
  2. TemplateJS *pParent = static_cast<TemplateJS *>(parent);
  3.  
  4. int argc = 0;
  5. char **argv = NULL;
  6. webworks::TemplateNDK *m_signalHandler = new webworks::TemplateNDK(pParent);
  7. m_signalHandler->doNetworkRequest(); //sending network request
  8.  
  9.  
  10. delete m_signalHandler;
  11. return NULL;
  12. }
  13.  
  14.  
  15. bool TemplateJS::StartThread(){
  16.  
  17. pthread_attr_t thread_attr;
  18. pthread_attr_init(&thread_attr);
  19. pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED);
  20.  
  21. pthread_t m_thread;
  22. pthread_create(&m_thread, &thread_attr, SignalThread, static_cast<void *>(this));
  23. pthread_attr_destroy(&thread_attr);
  24. if (!m_thread) {
  25. return true;
  26. } else {
  27. return false;
  28. }
  29. }
To copy to clipboard, switch view to plain text mode 

Here is my simple code to start request.

Qt Code:
  1. void TemplateNDK::doNetworkRequest()
  2. {
  3. _networkAccessManager = new QNetworkAccessManager();
  4.  
  5. QObject::connect(_networkAccessManager, SIGNAL(finished(QNetworkReply*)), this,
  6. SLOT(onRequestFinished(QNetworkReply*)));
  7.  
  8. QNetworkRequest request = QNetworkRequest();
  9. QString inputUrl = QString::fromUtf8(url.c_str());
  10. request.setUrl(QUrl(inputUrl));
  11. QNetworkReply* response = _networkAccessManager->get(request);
  12. }
To copy to clipboard, switch view to plain text mode 

When i call startThread() function first time slot returns proper response. But when I call same startThread() function second time it stuck and does not execute slot. QObject::connect is returning true both times.

If using QTimer to abort request after interval then second time onRequestFinished slot is getting executed and returns value of reply->error() as 5 that is "operation canceled".

Am i doing something wrong with QCoreApplication::exec().
Please help.

Thanks.