我正在使用下面的 win API 代码来捕获 Windows 桌面中的事件工作窗口标题。对于这个实现,Ubuntu 平台的 Qt 有任何替代方案吗?
QString getActiveWndTitle()
{
char buff[256];
HWND hwnd = GetForegroundWindow();
GetWindowText(hwnd, (LPWSTR) buff, 254);
QString title = QString::fromWCharArray((const wchar_t *)buff);
return title;
}
最佳答案
如果想获取Qt应用程序事件窗口的标题,可以使用
QApplication::activeWindow()->windowTitle();
如果没有,您可以使用 QProcess 运行 Ubuntu 命令。这是 xdotool 或(如果您不想安装任何东西)此命令:
xprop -id $(xprop -root _NET_ACTIVE_WINDOW | cut -d ' ' -f 5) WM_NAME | awk -F '"' '{print $2}'
关于c++ - 如何在 Ubuntu Qt 中获取事件窗口标题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49233573/