Hi,

I have some code which creates a thread which basically just emits a signal back to the worker thread which puts a string into a QListWidget. Problem is, the items in the list widget are not shown until the worker thread has finished what it was doing?

This is some of the code :

Qt Code:
  1. void CInitialiseThread::run()
  2. {
  3. while( !m_bStopped )
  4. {
  5. emit AddInfo();
  6. msleep( 10 );
  7. }
  8. }
To copy to clipboard, switch view to plain text mode 

Thread is created in the following function :

Qt Code:
  1. void CanView::LoadupDetails()
  2. {
  3. if( theApp->m_pWorkspace )
  4. {
  5.  
  6. m_pCanInitialiseThread = new CInitialiseThread();
  7.  
  8. connect( m_pCanInitialiseThread, SIGNAL(AddInfo()), this,
  9. SLOT(AddInfo()) );
  10.  
  11. if( !m_pCanInitialiseThread->isRunning() )
  12. {
  13. m_pCanInitialiseThread->start();
  14. }
  15.  
  16. QList<CCanChannel*>*pcanFilterObj = &theApp->m_pWorkspace->m_oCanChannels;
  17. if( pcanFilterObj )
  18. {
  19. for( int i = 0; i < pcanFilterObj->count(); i++ )
  20. {
  21. CCanChannel* pCanChannel = (CCanChannel*)pcanFilterObj->at( i );
  22. if( pCanChannel )
  23. {
  24. int nChannel = ui.canBox->currentIndex() + 1;
  25. QString strId;
  26. strId.sprintf( "%i", nChannel );
  27. if( pCanChannel->m_strCanChannel == strId )
  28. {
  29. // found channel we want
  30. int nBaud = ui.baudBox->findText( pCanChannel->m_strBaud );
  31. ui.baudBox->setCurrentIndex( nBaud );
  32. if( pCanChannel->m_pCanFilter )
  33. {
  34. // set extended flag and can id flag
  35. //ui.Extended->setChecked( pCanChannel->m_pCanFilter->m_bExtended );
  36. //ui.canIdCheck->setChecked( pCanChannel->m_pCanFilter->m_bFilterOnId );
  37.  
  38. //ui.canIdList->clear();
  39.  
  40. QString strId = "";
  41. // any filtering on canid's?
  42. for( int j = 0; j < pCanChannel->m_oFilterIdList.count(); j++ )
  43. {
  44. // ui.canIdList->addItem( pCanChannel->m_oFilterIdList.at(j) );
  45. int nHex = pCanChannel->m_oFilterIdList.at(j).toInt( 0, 16 );
  46. strId.sprintf( "%x", nHex );
  47. theApp->AddFilterByCanId( strId, theApp->GetChannelID()+1 );//1 );
  48. }
  49.  
  50.  
  51. CCanFilterDetails* pCanDetails;
  52. for( int jj = 0; jj < pCanChannel->m_pCanFilter->m_oCanFilterDetails.count(); jj++ )
  53. {
  54. pCanDetails = (CCanFilterDetails*)pCanChannel->m_pCanFilter->m_oCanFilterDetails.at(jj);
  55.  
  56. // Configure can - does passthruconnect for each filter
  57. long lFlags = 0;
  58. bool ok;
  59. int iMask = pCanDetails->m_strMask.toLong( &ok, 16 );
  60. int iPattern = pCanDetails->m_strAccept.toLong( &ok, 16 );
  61.  
  62. if( pCanChannel->m_pCanFilter->m_bExtended )
  63. lFlags = 0x100;
  64.  
  65. QString strFilterType = pCanDetails->m_strType;
  66. if( pCanChannel->m_pCanFilter->m_bExtended )
  67. lFlags = 0x100;
  68.  
  69. QString strCanChannel = pCanChannel->m_strCanChannel;// ui.canChannels->currentText();
  70. int nBaud = pCanChannel->m_strBaud.toInt();//ui.baudRate->currentText().toInt();
  71. int iReply = theApp->ConfigureCan( nBaud, nBaud, strCanChannel ); // configre can first
  72.  
  73. unsigned long iFilterId = SetFilter( pCanDetails->m_strMask, pCanDetails->m_strAccept, lFlags, 1, TRUE );
  74.  
  75.  
  76. }
  77. }
  78.  
  79. break;
  80. }
  81. }
  82.  
  83. }
  84. }
  85. }
  86. if( m_pCanInitialiseThread->isRunning() )
  87. {
  88. m_pCanInitialiseThread->stop();
  89. m_pCanInitialiseThread->wait();
  90. }
  91. }
To copy to clipboard, switch view to plain text mode 

The Addinfo basically just adds a QString to a QListWidget. I don't know why the QListWidget isn't being updated every 10ms?

Guess I'm doing something wrong or there is no CPU time?

Regards,
Steve