Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gamera_videos_no_ui
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liusq
gamera_videos_no_ui
Commits
7a9cb116
Commit
7a9cb116
authored
Oct 10, 2024
by
“liusq”
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改命令bug1
parent
fa9c2024
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
15 deletions
+28
-15
VidesData.h
+28
-15
No files found.
VidesData.h
View file @
7a9cb116
...
...
@@ -484,6 +484,8 @@ inline bool GetNetworkInfoByQNetworkInterface(QString &mac, QString &subnetMask,
}
inline
bool
pingAddress
(
const
QString
&
address
)
{
QProcess
cmd
;
#ifdef Q_OS_WIN
// Windows 指令 "ping IP -n 1 -w 超时(ms)"
QString
cmdstr
=
QString
(
"ping %1 -n 1 -w %2"
)
...
...
@@ -494,27 +496,38 @@ inline bool pingAddress(const QString &address) {
.
arg
(
address
);
#endif
QProcess
cmd
;
// 启动进程
cmd
.
start
(
cmdstr
);
cmd
.
waitForReadyRead
(
1000
);
cmd
.
waitForFinished
(
1000
);
QString
res
=
QString
::
fromLocal8Bit
(
cmd
.
readAll
());
qInfo
()
<<
res
;
// 等待进程准备好读取
if
(
!
cmd
.
waitForStarted
())
{
qWarning
()
<<
"Failed to start 'ping' process for"
<<
address
;
return
false
;
}
#ifdef Q_OS_WIN
if
(
res
.
indexOf
(
"TTL"
)
==
-
1
)
#else
if
(
!
res
.
contains
(
"1 packets transmitted, 1 received"
))
#endif
{
qInfo
()
<<
address
<<
QString
::
fromLocal8Bit
(
"ping不通"
);
// 等待进程完成
if
(
!
cmd
.
waitForFinished
(
3000
))
{
// 增加超时时间
cmd
.
kill
();
qWarning
()
<<
"Ping process timed out for"
<<
address
;
return
false
;
}
else
{
qInfo
()
<<
address
<<
QString
::
fromLocal8Bit
(
"ping通"
);
// 读取输出
QByteArray
output
=
cmd
.
readAllStandardOutput
();
QByteArray
errorOutput
=
cmd
.
readAllStandardError
();
int
exitCode
=
cmd
.
exitCode
();
qInfo
()
<<
"Ping Output for"
<<
address
<<
":"
<<
QString
::
fromUtf8
(
output
);
qInfo
()
<<
"Ping Error Output for"
<<
address
<<
":"
<<
QString
::
fromUtf8
(
errorOutput
);
qInfo
()
<<
"Ping Exit Code for"
<<
address
<<
":"
<<
exitCode
;
// 判断 Ping 是否成功
if
(
exitCode
==
0
)
{
qInfo
()
<<
address
<<
"ping通"
;
return
true
;
}
else
{
qInfo
()
<<
address
<<
"ping不通"
;
return
false
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment