其实代码没什么,一个定时器处理函数,一个处理鼠标点击的槽函数
定时器函数
void MainWnd::packSendData()
{
QReadWriteLock lock;
DATA_PACK *pdatapack;
int index = 0;
unsigned short crcValue = 0;
memset(sendBuf,0,sizeof(sendBuf));
sendBuf[index++] = 0x01;
sendBuf[index++] = 0x04;
sendBuf[index++] = 0x01;
sendBuf[index++] = 0x00;
sendBuf[index++] = 0x00;
sendBuf[index++] = 0x23;
crcValue = cal_crc((unsigned char*)sendBuf,6);
sendBuf[index++] = crcValue&0xFF;
sendBuf[index++] = crcValue>>8;
pdatapack = new DATA_PACK;
memcpy(pdatapack->databuf ,sendBuf,8);
QWriteLocker locker(&lock);
dataQueue.enqueue(pdatapack);
locker.unlock();
index = 0;
sendBuf[index++] = 0x01;
sendBuf[index++] = 0x04;
sendBuf[index++] = 0x00;
sendBuf[index++] = 0x00;
sendBuf[index++] = 0x00;
sendBuf[index++] = 0x30;
crcValue = cal_crc((unsigned char*)sendBuf,6);
sendBuf[index++] = crcValue&0xFF;
sendBuf[index++] = crcValue>>8;
pdatapack = new DATA_PACK;
memcpy(pdatapack->databuf ,sendBuf,8);
locker.relock();
dataQueue.enqueue(pdatapack);
locker.unlock();
qDebug()<<QThread::currentThreadId();
}