Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
chain78
qtcpp_demo
提交
2b4519ce
qtcpp_demo
项目概览
chain78
/
qtcpp_demo
与 Fork 源项目一致
Fork自
colorEagleStdio / qtcpp_demo
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
qtcpp_demo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2b4519ce
编写于
1月 23, 2021
作者:
丁劲犇
😸
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
windows stdout redirect is still under develop
上级
a70421f6
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
75 addition
and
15 deletion
+75
-15
uhd_cpp/uhd_spectrum/main.cpp
uhd_cpp/uhd_spectrum/main.cpp
+1
-1
uhd_cpp/uhd_spectrum/specwidget.ui
uhd_cpp/uhd_spectrum/specwidget.ui
+8
-12
uhd_cpp/uhd_spectrum/stdout_watcher.cpp
uhd_cpp/uhd_spectrum/stdout_watcher.cpp
+61
-1
uhd_cpp/uhd_spectrum/stdout_watcher.h
uhd_cpp/uhd_spectrum/stdout_watcher.h
+5
-1
未找到文件。
uhd_cpp/uhd_spectrum/main.cpp
浏览文件 @
2b4519ce
#include "specwidget.h"
#
include
"specwidget.h"
#ifdef __GNUC__
#include <unistd.h>
#endif
...
...
uhd_cpp/uhd_spectrum/specwidget.ui
浏览文件 @
2b4519ce
...
...
@@ -23,10 +23,6 @@
<property
name=
"text"
>
<string>
Start
</string>
</property>
<property
name=
"icon"
>
<iconset>
<normaloff>
:/icons/icons/signal.svg
</normaloff>
:/icons/icons/signal.svg
</iconset>
</property>
</widget>
</item>
<item>
...
...
@@ -225,8 +221,8 @@
<rect>
<x>
0
</x>
<y>
0
</y>
<width>
3
1
0
</width>
<height>
4
50
</height>
<width>
3
2
0
</width>
<height>
4
78
</height>
</rect>
</property>
<attribute
name=
"label"
>
...
...
@@ -370,8 +366,8 @@
<rect>
<x>
0
</x>
<y>
0
</y>
<width>
3
1
0
</width>
<height>
165
</height>
<width>
3
2
0
</width>
<height>
478
</height>
</rect>
</property>
<attribute
name=
"label"
>
...
...
@@ -534,8 +530,8 @@
<rect>
<x>
0
</x>
<y>
0
</y>
<width>
3
1
0
</width>
<height>
4
50
</height>
<width>
3
2
0
</width>
<height>
4
78
</height>
</rect>
</property>
<attribute
name=
"label"
>
...
...
@@ -562,8 +558,8 @@
<rect>
<x>
0
</x>
<y>
0
</y>
<width>
3
1
0
</width>
<height>
4
50
</height>
<width>
3
2
0
</width>
<height>
4
78
</height>
</rect>
</property>
<attribute
name=
"label"
>
...
...
uhd_cpp/uhd_spectrum/stdout_watcher.cpp
浏览文件 @
2b4519ce
#include "stdout_watcher.h"
#
include
"stdout_watcher.h"
#include <stdio.h>
#include <thread>
#ifdef __GNUC__
...
...
@@ -7,6 +7,11 @@
#include <sys/stat.h>
#include <fcntl.h>
#endif
#ifdef _MSVC_LANG
#include <io.h>
#include <fcntl.h>
#endif
stdout_watcher
::
stdout_watcher
(
QObject
*
parent
)
:
QThread
(
parent
),
m_bStop
(
false
)
{
...
...
@@ -15,8 +20,63 @@ stdout_watcher::stdout_watcher(QObject *parent) : QThread(parent),
void
stdout_watcher
::
stop_and_wait
()
{
m_bStop
=
true
;
fprintf
(
stdout
,
"Bye!
\n
"
);
fprintf
(
stderr
,
"Bye!
\n
"
);
wait
();
}
#ifdef _MSVC_LANG
void
stdout_watcher
::
run
()
{
return
;
auto
pt
=
[
&
](
FILE
*
stda
,
bool
stderrb
)
->
void
{
HANDLE
hOutputReadTmp
=
0
;
HANDLE
hOutputWrite
=
0
;
if
(
!
CreatePipe
(
&
hOutputReadTmp
,
&
hOutputWrite
,
0
,
0
))
emit
evt_stdata
(
"[stdout watcher]:CreatePipe Error."
,
stderrb
);
int
hCrt
=
_open_osfhandle
(
(
long
)
hOutputWrite
,
_O_TEXT
);
FILE
*
hf
=
_fdopen
(
hCrt
,
"w"
);
*
stda
=
*
hf
;
int
i
=
setvbuf
(
stda
,
NULL
,
_IONBF
,
0
);
CHAR
lpBuffer
[
1024
];
DWORD
nBytesRead
;
while
(
!
m_bStop
)
{
if
(
!
ReadFile
(
hOutputReadTmp
,
lpBuffer
,
sizeof
(
lpBuffer
),
&
nBytesRead
,
NULL
)
||
!
nBytesRead
)
{
if
(
GetLastError
()
==
ERROR_BROKEN_PIPE
)
break
;
// pipe done - normal exit path.
else
emit
evt_stdata
(
"ReadFile"
,
stderrb
);
}
if
(
nBytesRead
>
0
)
{
emit
evt_stdata
(
QByteArray
(
lpBuffer
,
nBytesRead
),
stderrb
);
}
}
fclose
(
hf
);
_close
(
hCrt
);
CloseHandle
(
hOutputReadTmp
);
CloseHandle
(
hOutputWrite
);
};
std
::
thread
t1
(
pt
,
stderr
,
true
);
std
::
thread
t2
(
pt
,
stdout
,
false
);
t1
.
join
();
t2
.
join
();
}
#endif
#ifdef __GNUC__
void
stdout_watcher
::
run
()
...
...
uhd_cpp/uhd_spectrum/stdout_watcher.h
浏览文件 @
2b4519ce
#ifndef STDOUT_WATCHER_H
#
ifndef
STDOUT_WATCHER_H
#define STDOUT_WATCHER_H
#include <QThread>
#include <atomic>
#ifdef _MSVC_LANG
#include<windows.h>
#endif
class
stdout_watcher
:
public
QThread
{
Q_OBJECT
...
...
@@ -14,6 +17,7 @@ signals:
void
evt_stdata
(
QByteArray
,
bool
stderrb
);
public:
std
::
atomic
<
bool
>
m_bStop
;
};
#endif // STDOUT_WATCHER_H
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录