Qt5 embedded window 保持独立,不显示在我自己的

Qt5 embedded window stays independent and isn't being displayed in my own

我一直在努力学习如何在 Qt5 中为我的游戏引擎嵌入 window。我从 xwininfo 获取 window id。这是有效的,fromWinId 不是 return nullptr。该应用程序运行没有错误,但 window 没有显示任何内容,嵌入式应用程序独立于我的 window.

我的 window 有一些背景泄露了。 Here is a screenshot(泄漏的 window 不是我要嵌入的那个)

这是我的代码,我正在用 Clang 11 和 Qt 5.15.1 编译,运行 在 Debian 上用 X11 编译。

#include <QApplication>
#include <QGridLayout>
#include <QWidget>
#include <QWindow>
#include <iostream>

class main_window : public QWidget
{
public:
    explicit main_window(const uint32_t wid)
    {
        QWindow* window = QWindow::fromWinId((WId)wid);
        window->setFlags(Qt::FramelessWindowHint);

        QWidget* widget = QWidget::createWindowContainer(window);
        widget->setParent(this);

        auto* layout = new QGridLayout{};
        layout->addWidget(widget);
        setLayout(layout);
    }
};

int main(int argc, char** const argv)
{
    QApplication app{argc, argv};

    uint32_t wid;
    std::cin >> wid;

    main_window window{wid};
    window.show();

    return QApplication::exec();
}

提前致谢。

原来解决方法是将 window id 作为十进制值而不是十六进制值传递。不过很奇怪,因为没有任何错误。