Zk.Sun 2022-05-16 13:45 采纳率: 50%
浏览 168
已结题

关于Ubuntu下将外部软件窗口嵌入到Qt窗体中的一些问题

编译环境Ubuntu18.04 Qt5.13.2
class WindowsMatchingPid
{
public:
    WindowsMatchingPid(Display *display, Window wRoot, unsigned long pid)
        : _display(display),
          _pid(pid)
    {
        // Get the PID property atom.
        _atomPID = XInternAtom(display, "_NET_WM_PID", True);
        if(_atomPID == None)
        {
            std::cout << "No such atom" << std::endl;
            return;
        }

        search(wRoot);
    }

    const std::list<Window> &result() const { return _result; }

private:
    unsigned long  _pid;
    Atom           _atomPID;
    Display       *_display;
    std::list<Window>   _result;

    void
    search(Window w)
    {
        // Get the PID for the current Window.
        Atom           type;
        int            format;
        unsigned long  nItems;
        unsigned long  bytesAfter;
        unsigned char *propPID = 0;
        if(Success == XGetWindowProperty(
                    _display,
                    w,
                    _atomPID,
                    0,
                    1,
                    False,
                    XA_CARDINAL,
                    &type,
                    &format,
                    &nItems,
                    &bytesAfter,
                    &propPID))
        {
            if(propPID != 0)
            {
                // If the PID matches, add this window to the result set.
                if(_pid == *((unsigned long *)propPID))
                {
                    _result.push_back(w);
                }

                XFree(propPID);
            }
        }

        // Recurse into child windows.
        Window    wRoot;
        Window    wParent;
        Window   *wChild;
        unsigned  nChildren;
        if(0 != XQueryTree(_display, w, &wRoot, &wParent, &wChild, &nChildren))
        {
            for(unsigned i = 0; i < nChildren; i++)
                search(wChild[i]);
        }

        //XFree(propPID);
    }
};


unsigned long
get_win_id_from_pid(qint64 pid)
{
    //std::cout << "Searching for windows associated with PID " << pid << std::endl;

    // Start with the root window.
    Display *display = XOpenDisplay(0);

    WindowsMatchingPid match(display, XDefaultRootWindow(display), pid);

    // Print the result.
    const std::list<Window> &result = match.result();

    long win_id = 0;
    for(std::list<Window>::const_iterator pos = result.begin(); pos != result.end(); pos++)
    {
        std::cout << "Window #" << (unsigned long)(*pos) << std::endl;
        win_id = (unsigned long)(*pos);
    }

    return win_id;
}

运行结果及报错内容

:-1: error: mainwindow.o: undefined reference to symbol 'XFree'
/usr/lib/x86_64-linux-gnu/libX11.so.6:-1: error: error adding symbols: DSO missing from command line
:-1: error: collect2: error: ld returned 1 exit status

我的解答思路和尝试过的方法

尝试重新安装x11也不能解决问题,大家有没有遇到过呢?求解

我想要达到的结果
  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 5月24日
    • 创建了问题 5月16日

    悬赏问题

    • ¥15 ansys fluent计算闪退
    • ¥15 有关wireshark抓包的问题
    • ¥15 需要写计算过程,不要写代码,求解答,数据都在图上
    • ¥15 向数据表用newid方式插入GUID问题
    • ¥15 multisim电路设计
    • ¥20 用keil,写代码解决两个问题,用库函数
    • ¥50 ID中开关量采样信号通道、以及程序流程的设计
    • ¥15 U-Mamba/nnunetv2固定随机数种子
    • ¥15 vba使用jmail发送邮件正文里面怎么加图片
    • ¥15 vb6.0如何向数据库中添加自动生成的字段数据。