Bootstrap

用QT制作含有对话框的dll-血泪教训

一,修改pro:

这个dll的pro文件,一定要:
 

QT += core gui widgets

二、windeployqt

三、创建 QApplication 实例

#include <QApplication>
#include <QWidget>
#include <QPushButton>
#include <QVBoxLayout>

extern "C" __declspec(dllexport) void ShowWindow()
{
    // 手动构造 argc 和 argv
    int argc = 0; // 模拟没有命令行参数
    char** argv = nullptr;

    // 创建 QApplication 实例
    QApplication app(argc, argv); // 正确传递 argc 和 argv

    // 创建窗口和按钮
    QWidget window;
    window.setWindowTitle("Qt Window from DLL");
    window.resize(400, 300);

    QPushButton button("Close", &window);
    QVBoxLayout *layout = new QVBoxLayout;
    layout->addWidget(&button);
    window.setLayout(layout);

    // 连接按钮点击信号到窗口关闭槽
    QObject::connect(&button, &QPushButton::clicked, &window, &QWidget::close);

    // 显示窗口并启动事件循环
    window.show();
    app.exec(); // 启动事件循环
}