mirror of
https://github.com/barry-ran/QtScrcpy.git
synced 2025-08-04 14:48:37 +00:00
fix:完善获取ip方式
This commit is contained in:
parent
67ed9d9bd5
commit
77fa44ca8f
2 changed files with 27 additions and 4 deletions
|
@ -62,14 +62,16 @@ void AdbProcess::initSignals()
|
||||||
|
|
||||||
connect(this, &QProcess::readyReadStandardError, this,
|
connect(this, &QProcess::readyReadStandardError, this,
|
||||||
[this](){
|
[this](){
|
||||||
m_errorOutput = QString::fromLocal8Bit(readAllStandardError()).trimmed();
|
QString tmp = QString::fromLocal8Bit(readAllStandardError()).trimmed();
|
||||||
qWarning(QString("AdbProcess::error:%1").arg(m_errorOutput).toUtf8());
|
m_errorOutput += tmp;
|
||||||
|
qWarning(QString("AdbProcess::error:%1").arg(tmp).toUtf8());
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(this, &QProcess::readyReadStandardOutput, this,
|
connect(this, &QProcess::readyReadStandardOutput, this,
|
||||||
[this](){
|
[this](){
|
||||||
m_standardOutput = QString::fromLocal8Bit(readAllStandardOutput()).trimmed();
|
QString tmp = QString::fromLocal8Bit(readAllStandardOutput()).trimmed();
|
||||||
qInfo(QString("AdbProcess::out:%1").arg(m_standardOutput).toUtf8());
|
m_standardOutput += tmp;
|
||||||
|
qInfo(QString("AdbProcess::out:%1").arg(tmp).toUtf8());
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(this, &QProcess::started, this,
|
connect(this, &QProcess::started, this,
|
||||||
|
@ -125,12 +127,22 @@ QStringList AdbProcess::getDevicesSerialFromStdOut()
|
||||||
QString AdbProcess::getDeviceIPFromStdOut()
|
QString AdbProcess::getDeviceIPFromStdOut()
|
||||||
{
|
{
|
||||||
QString ip = "";
|
QString ip = "";
|
||||||
|
#if 0
|
||||||
QString strIPExp = "inet [\\d.]*";
|
QString strIPExp = "inet [\\d.]*";
|
||||||
QRegExp ipRegExp(strIPExp,Qt::CaseInsensitive);
|
QRegExp ipRegExp(strIPExp,Qt::CaseInsensitive);
|
||||||
if (ipRegExp.indexIn(m_standardOutput) != -1) {
|
if (ipRegExp.indexIn(m_standardOutput) != -1) {
|
||||||
ip = ipRegExp.cap(0);
|
ip = ipRegExp.cap(0);
|
||||||
ip = ip.right(ip.size() - 5);
|
ip = ip.right(ip.size() - 5);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
QString strIPExp = "inet addr:[\\d.]*";
|
||||||
|
QRegExp ipRegExp(strIPExp,Qt::CaseInsensitive);
|
||||||
|
if (ipRegExp.indexIn(m_standardOutput) != -1) {
|
||||||
|
ip = ipRegExp.cap(0);
|
||||||
|
ip = ip.right(ip.size() - 10);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return ip;
|
return ip;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,11 @@ Dialog::Dialog(QWidget *parent) :
|
||||||
if (!ip.isEmpty()) {
|
if (!ip.isEmpty()) {
|
||||||
ui->deviceIpEdt->setText(ip);
|
ui->deviceIpEdt->setText(ip);
|
||||||
}
|
}
|
||||||
|
} else if (args.contains("ifconfig") && args.contains("wlan0")) {
|
||||||
|
QString ip = m_adb.getDeviceIPFromStdOut();
|
||||||
|
if (!ip.isEmpty()) {
|
||||||
|
ui->deviceIpEdt->setText(ip);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -207,6 +212,7 @@ void Dialog::on_getIPBtn_clicked()
|
||||||
// or
|
// or
|
||||||
// adb -s P7C0218510000537 shell ip -f inet addr show wlan0
|
// adb -s P7C0218510000537 shell ip -f inet addr show wlan0
|
||||||
QStringList adbArgs;
|
QStringList adbArgs;
|
||||||
|
#if 0
|
||||||
adbArgs << "shell";
|
adbArgs << "shell";
|
||||||
adbArgs << "ip";
|
adbArgs << "ip";
|
||||||
adbArgs << "-f";
|
adbArgs << "-f";
|
||||||
|
@ -214,6 +220,11 @@ void Dialog::on_getIPBtn_clicked()
|
||||||
adbArgs << "addr";
|
adbArgs << "addr";
|
||||||
adbArgs << "show";
|
adbArgs << "show";
|
||||||
adbArgs << "wlan0";
|
adbArgs << "wlan0";
|
||||||
|
#else
|
||||||
|
adbArgs << "shell";
|
||||||
|
adbArgs << "ifconfig";
|
||||||
|
adbArgs << "wlan0";
|
||||||
|
#endif
|
||||||
m_adb.execute(ui->serialBox->currentText().trimmed(), adbArgs);
|
m_adb.execute(ui->serialBox->currentText().trimmed(), adbArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue