子程序主要代码
#include "ChildWidgets.h"
#include <QtWidgets/QApplication>
#include <QWindow>
#include <iostream>
#include <QMessageBox>
#include <thread>
int main(int argc, char* argv[])
{
QApplication a(argc, argv);
ChildWidgets w;
w.show();
w.createWinId();
std::cerr << w.winId() << std::endl;
return a.exec();
}
主程序主要代码
InWidgets::InWidgets(QWidget* parent)
: QMainWindow(parent)
{
this->resize(600, 400);
QString path = QCoreApplication::applicationDirPath();
path += "/ChildWidgets.exe";
process = new QProcess(this);
connect(process, &QProcess::readyReadStandardError, [&]() {
quint64 winId = process->readAllStandardError().toLongLong();
QWindow* childWin = QWindow::fromWinId(winId);
if (childWin)
{
QWidget* widget = QWidget::createWindowContainer(childWin);
this->setCentralWidget(widget);
}
});
process->start(path);
process->setParent(this);
}
结果
地址:https://download.csdn.net/download/qq_44575789/85800705