Qt 6.5 引入了
ScreenCapture
类,它应该记录屏幕。
检查一个例子
我试过以下方法:
ApplicationWindow {
id: root
MouseArea {
id: recording
anchors.fill: parent
property bool inProcess: false
onClicked: {
if (recording.inProcess) {
screenCapture.active = recording.inProcess = false;
recorder.stop();
} else {
screenCapture.active = recording.inProcess = true;
recorder.record();
}
}
}
CaptureSession {
id: captureSession
screenCapture: ScreenCapture {
id: screenCapture
active: false
}
recorder: MediaRecorder {
id: recorder
mediaFormat {
fileFormat: MediaFormat.MPEG4
videoCodec: MediaFormat.VideoCodec.H265
}
outputLocation: "desired-name.mp4"
quality: MediaRecorder.HighQuality
}
}
}
这就是工作!
但后来我想捕捉一个窗口,而不是整个屏幕。 由于documentation,
ScreenCapture
有一个window
属性来实现这一点,但是当我添加
window: root
到它,我得到一个错误:Cannot assign to non-existent property "window"
它是 Qt 6.5 中的错误还是我遗漏了什么?
明白了,Qt6.5.0因为bug已经去掉了