XrayCtrlViewModel *XrayCtrlViewModel::sm_pInstance = nullptr;
QMutex XrayCtrlViewModel::sm_mutex;
XrayCtrlViewModel *XrayCtrlViewModel::SharedInstance()
{
if (sm_pInstance == nullptr) {
sm_mutex.lock();
if (sm_pInstance == nullptr) {
sm_pInstance = new XrayCtrlViewModel();
}
}
return sm_pInstance;
}
XrayCtrlViewModel *xrayVM = XrayCtrlViewModel::SharedInstance();
connect(xrayVM, &XrayCtrlViewModel::sig_didUpdateCurrentState, this, [this, doorStateLabel, xrayStateLabel, warmStateLabel, kvLabel, uALabel](SerialPortItem *item){
bool interLock = item->interLock;
if (interLock) {
doorStateLabel->setStyleSheet("background: #2793ff; border-radius: 7px;");
}
else {
doorStateLabel->setStyleSheet("background: #ff3a3a; border-radius: 7px;");
}
bool isXrayOn = item->isXrayOn;
if (isXrayOn) {
xrayStateLabel->setStyleSheet("background: #ff3a3a; border-radius: 7px;");
}
else {
xrayStateLabel->setStyleSheet("background: #2793ff; border-radius: 7px;");
}
bool isWarmingUp = item->isWarmingUp;
if (isWarmingUp) {
warmStateLabel->setStyleSheet("background: #ff3a3a; border-radius: 7px;");
}
else {
warmStateLabel->setStyleSheet("background: #2793ff; border-radius: 7px;");
}
kvLabel->setText(QString(u8"电压: %1kV").arg(item->kv));
uALabel->setText(QString(u8"电流: %1uA").arg(item->ua));
});
【qt】单例模式
于 2024-06-21 14:29:31 首次发布