diff --git a/core_qui/quihelper.cpp b/core_qui/quihelper.cpp index 527e3ea7..b7bf06d4 100644 --- a/core_qui/quihelper.cpp +++ b/core_qui/quihelper.cpp @@ -1013,10 +1013,32 @@ QString QUIHelper::getNetIP(const QString &html) return ip; } +const QString getHostServer() +{ + QString ipAddress; + + // 获取第一个本主机的 IPv4 地址 + QList addresss = QNetworkInterface::allAddresses(); + foreach (const QHostAddress &addr, addresss) { + if ((addr != QHostAddress::LocalHost) && (addr.protocol() == QAbstractSocket::IPv4Protocol)) { + ipAddress = addr.toString(); + break; + } + } + + // 如果没有找到,则以本地 IP 地址为准 + if (ipAddress.isEmpty()) + ipAddress = QHostAddress(QHostAddress::LocalHost).toString(); + + return ipAddress; +} + QString QUIHelper::getLocalIP() { //优先取192开头的IP,如果获取不到IP则取127.0.0.1 - QString ip = "127.0.0.1"; +// QString ip = "127.0.0.1"; + + QString ip = getHostServer(); QStringList ips = getLocalIPs(); foreach (QString str, ips) { if (str.startsWith("192.168.1") || str.startsWith("192")) { @@ -1024,7 +1046,6 @@ QString QUIHelper::getLocalIP() break; } } - return ip; } diff --git a/devicebutton/frmdevicebutton.cpp b/devicebutton/frmdevicebutton.cpp index 7d8da86d..8ba53b5e 100644 --- a/devicebutton/frmdevicebutton.cpp +++ b/devicebutton/frmdevicebutton.cpp @@ -40,12 +40,18 @@ void frmDeviceButton::initForm() foreach (QPushButton *btn, btnColor) { connect(btn, SIGNAL(clicked(bool)), this, SLOT(changeColor())); } + + //初始化获取当前按钮类型,设置焦点 + int initstatus = btn1->getButtonStyle(); + if(initstatus >= DeviceButton::ButtonStyle_Circle || initstatus<= DeviceButton::ButtonStyle_Msg2) + btnStyle.at(initstatus)->setFocus(); } void frmDeviceButton::changeStyle() { QPushButton *btn = (QPushButton *)sender(); int index = btnStyle.indexOf(btn); + btn->setFocus(); DeviceButton::ButtonStyle style = (DeviceButton::ButtonStyle)index; btn1->setButtonStyle(style); btn2->setButtonStyle(style); @@ -56,6 +62,7 @@ void frmDeviceButton::changeColor() { QPushButton *btn = (QPushButton *)sender(); int index = btnColor.indexOf(btn); + btn->setFocus(); DeviceButton::ButtonColor style = (DeviceButton::ButtonColor)index; btn1->setButtonColor(style); btn2->setButtonColor(style);