steg90
28th September 2007, 09:43
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 :
void CInitialiseThread::run()
{
while( !m_bStopped )
{
emit AddInfo();
msleep( 10 );
}
}
Thread is created in the following function :
void CanView::LoadupDetails()
{
if( theApp->m_pWorkspace )
{
m_pCanInitialiseThread = new CInitialiseThread();
connect( m_pCanInitialiseThread, SIGNAL(AddInfo()), this,
SLOT(AddInfo()) );
if( !m_pCanInitialiseThread->isRunning() )
{
m_pCanInitialiseThread->start();
}
QList<CCanChannel*>*pcanFilterObj = &theApp->m_pWorkspace->m_oCanChannels;
if( pcanFilterObj )
{
for( int i = 0; i < pcanFilterObj->count(); i++ )
{
CCanChannel* pCanChannel = (CCanChannel*)pcanFilterObj->at( i );
if( pCanChannel )
{
int nChannel = ui.canBox->currentIndex() + 1;
QString strId;
strId.sprintf( "%i", nChannel );
if( pCanChannel->m_strCanChannel == strId )
{
// found channel we want
int nBaud = ui.baudBox->findText( pCanChannel->m_strBaud );
ui.baudBox->setCurrentIndex( nBaud );
if( pCanChannel->m_pCanFilter )
{
// set extended flag and can id flag
//ui.Extended->setChecked( pCanChannel->m_pCanFilter->m_bExtended );
//ui.canIdCheck->setChecked( pCanChannel->m_pCanFilter->m_bFilterOnId );
//ui.canIdList->clear();
QString strId = "";
// any filtering on canid's?
for( int j = 0; j < pCanChannel->m_oFilterIdList.count(); j++ )
{
// ui.canIdList->addItem( pCanChannel->m_oFilterIdList.at(j) );
int nHex = pCanChannel->m_oFilterIdList.at(j).toInt( 0, 16 );
strId.sprintf( "%x", nHex );
theApp->AddFilterByCanId( strId, theApp->GetChannelID()+1 );//1 );
}
CCanFilterDetails* pCanDetails;
for( int jj = 0; jj < pCanChannel->m_pCanFilter->m_oCanFilterDetails.count(); jj++ )
{
pCanDetails = (CCanFilterDetails*)pCanChannel->m_pCanFilter->m_oCanFilterDetails.at(jj);
// Configure can - does passthruconnect for each filter
long lFlags = 0;
bool ok;
int iMask = pCanDetails->m_strMask.toLong( &ok, 16 );
int iPattern = pCanDetails->m_strAccept.toLong( &ok, 16 );
if( pCanChannel->m_pCanFilter->m_bExtended )
lFlags = 0x100;
QString strFilterType = pCanDetails->m_strType;
if( pCanChannel->m_pCanFilter->m_bExtended )
lFlags = 0x100;
QString strCanChannel = pCanChannel->m_strCanChannel;// ui.canChannels->currentText();
int nBaud = pCanChannel->m_strBaud.toInt();//ui.baudRate->currentText().toInt();
int iReply = theApp->ConfigureCan( nBaud, nBaud, strCanChannel ); // configre can first
unsigned long iFilterId = SetFilter( pCanDetails->m_strMask, pCanDetails->m_strAccept, lFlags, 1, TRUE );
}
}
break;
}
}
}
}
}
if( m_pCanInitialiseThread->isRunning() )
{
m_pCanInitialiseThread->stop();
m_pCanInitialiseThread->wait();
}
}
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
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 :
void CInitialiseThread::run()
{
while( !m_bStopped )
{
emit AddInfo();
msleep( 10 );
}
}
Thread is created in the following function :
void CanView::LoadupDetails()
{
if( theApp->m_pWorkspace )
{
m_pCanInitialiseThread = new CInitialiseThread();
connect( m_pCanInitialiseThread, SIGNAL(AddInfo()), this,
SLOT(AddInfo()) );
if( !m_pCanInitialiseThread->isRunning() )
{
m_pCanInitialiseThread->start();
}
QList<CCanChannel*>*pcanFilterObj = &theApp->m_pWorkspace->m_oCanChannels;
if( pcanFilterObj )
{
for( int i = 0; i < pcanFilterObj->count(); i++ )
{
CCanChannel* pCanChannel = (CCanChannel*)pcanFilterObj->at( i );
if( pCanChannel )
{
int nChannel = ui.canBox->currentIndex() + 1;
QString strId;
strId.sprintf( "%i", nChannel );
if( pCanChannel->m_strCanChannel == strId )
{
// found channel we want
int nBaud = ui.baudBox->findText( pCanChannel->m_strBaud );
ui.baudBox->setCurrentIndex( nBaud );
if( pCanChannel->m_pCanFilter )
{
// set extended flag and can id flag
//ui.Extended->setChecked( pCanChannel->m_pCanFilter->m_bExtended );
//ui.canIdCheck->setChecked( pCanChannel->m_pCanFilter->m_bFilterOnId );
//ui.canIdList->clear();
QString strId = "";
// any filtering on canid's?
for( int j = 0; j < pCanChannel->m_oFilterIdList.count(); j++ )
{
// ui.canIdList->addItem( pCanChannel->m_oFilterIdList.at(j) );
int nHex = pCanChannel->m_oFilterIdList.at(j).toInt( 0, 16 );
strId.sprintf( "%x", nHex );
theApp->AddFilterByCanId( strId, theApp->GetChannelID()+1 );//1 );
}
CCanFilterDetails* pCanDetails;
for( int jj = 0; jj < pCanChannel->m_pCanFilter->m_oCanFilterDetails.count(); jj++ )
{
pCanDetails = (CCanFilterDetails*)pCanChannel->m_pCanFilter->m_oCanFilterDetails.at(jj);
// Configure can - does passthruconnect for each filter
long lFlags = 0;
bool ok;
int iMask = pCanDetails->m_strMask.toLong( &ok, 16 );
int iPattern = pCanDetails->m_strAccept.toLong( &ok, 16 );
if( pCanChannel->m_pCanFilter->m_bExtended )
lFlags = 0x100;
QString strFilterType = pCanDetails->m_strType;
if( pCanChannel->m_pCanFilter->m_bExtended )
lFlags = 0x100;
QString strCanChannel = pCanChannel->m_strCanChannel;// ui.canChannels->currentText();
int nBaud = pCanChannel->m_strBaud.toInt();//ui.baudRate->currentText().toInt();
int iReply = theApp->ConfigureCan( nBaud, nBaud, strCanChannel ); // configre can first
unsigned long iFilterId = SetFilter( pCanDetails->m_strMask, pCanDetails->m_strAccept, lFlags, 1, TRUE );
}
}
break;
}
}
}
}
}
if( m_pCanInitialiseThread->isRunning() )
{
m_pCanInitialiseThread->stop();
m_pCanInitialiseThread->wait();
}
}
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