c++ - 如何在 Ubuntu Qt 中获取事件窗口标题?

标签 c++ qt ubuntu

我正在使用下面的 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/

相关文章:

c++ - QT线程,信号顺序

c++ - 如何在 Qt 中为 qmake 指定一个库文件依赖?

bash - shopt 在 shell 函数中不起作用

Python - Ubuntu OS 中的 Selenium 错误 : [Errno 20] Not a directory

c++ - 两个 std::vector 的 union 读取访问冲突

c++ - UDP 套接字是将接收到的数据划分为不同的消息,还是 recv 一次读取尽可能多的数据?

c++ - 回调和函数指针有什么关系?

javascript - QGraphicsWebView : create a text file using Javascript

c++ - 在 FTP 服务器中实现 "TYPE A"

ruby-on-rails - 无法在 Ubuntu Server 18.04 上安装 Phusion Passenger