C++ (Qt)void QSender::run(){ while(1) { if(!mainTable->ARP_cash.isEmpty()) { // QList<TableModel::ARP>::const_iterator i; // for (i = mainTable->ARP_cash.constBegin(); i != mainTable->ARP_cash.constEnd(); ++i) // { // if(((TableModel::ARP)*i).widget->isStarted()) // { // //arp.widget->isUDP()?SendUdpECHO(arp):SendECHO(arp); // msleep(5); // } // } foreach(TableModel::ARP arp,mainTable->ARP_cash) { // if(arp.widget->isStarted()) // { // //arp.widget->isUDP()?SendUdpECHO(arp):SendECHO(arp); // msleep(5); // } } } } }
if(!sender->isRunning()) sender->start(); mainTable->AddRecord("192.168.0.1",QString("001A9236F347").toAscii()); mainTable->AddRecord("192.168.0.2",QString("001A9236F357").toAscii()); mainTable->AddRecord("192.168.0.3",QString("001A9236F367").toAscii()); mainTable->AddRecord("192.168.0.4",QString("001A9236F387").toAscii());
mainTable->AddRecord("192.168.0.1",QString("001A9236F347").toAscii()); mainTable->AddRecord("192.168.0.2",QString("001A9236F357").toAscii()); mainTable->AddRecord("192.168.0.3",QString("001A9236F367").toAscii()); mainTable->AddRecord("192.168.0.4",QString("001A9236F387").toAscii()); if(!sender->isRunning()) sender->start();
C++ (Qt)mainTable->AddRecord("192.168.0.1",QString("001A9236F347").toAscii()); mainTable->AddRecord("192.168.0.2",QString("001A9236F357").toAscii()); mainTable->AddRecord("192.168.0.3",QString("001A9236F367").toAscii()); mainTable->AddRecord("192.168.0.4",QString("001A9236F387").toAscii()); if(!sender->isRunning()) sender->start(); mainTable->AddRecord("192.168.0.5",QString("001A9236F348").toAscii()); mainTable->AddRecord("192.168.0.6",QString("001A9236F359").toAscii()); mainTable->AddRecord("192.168.0.7",QString("001A9236F360").toAscii()); mainTable->AddRecord("192.168.0.8",QString("001A9236F381").toAscii());
class TableModel{...private: QMutex mutex;...}void TableModel::AddRecord(QString IPaddress, QByteArray MACaddress){ QMutexLocker locker(&mutex); ...}void TableModel::SomeFunction(){ QMutexLocker locker(&mutex); ... foreach(TableModel::ARP arp,mainTable->ARP_cash) { ... } ...}void QSender::run(){ .... mainTable->SomeFunction(); ....}
C++ (Qt)void Sender::run( void ){ while (true) { theSemaphore.acquire(); if (mStopFlag) break; QMutexLocker(&theMutex); // тут крутите foreach и всю любовь }}
C++ (Qt)QMutexLocker(&theMutex); // ждем пока Sender не освободит mainTable->AddRecord("192.168.0.1",QString("001A9236F347").toAscii());...theSemaphore.release(); // будим Sender'а