Skip to content

Qt 6.9: Build succeeds but crashes on run #218

@wslyw

Description

@wslyw

Here's my code:

CMainUI::CMainUI():
   ui(new Ui::CMainUI)
{
    m_pWindwoBar = new QWK::WindowBar;

    QWK::WidgetWindowAgent* agent = new QWK::WidgetWindowAgent(this);
    agent->setup(this);

    agent->setTitleBar(m_pWindwoBar);

    agent->setSystemButton(QWK::WindowAgentBase::WindowIcon, m_pWindwoBar->iconButton());
    agent->setSystemButton(QWK::WindowAgentBase::Minimize, m_pWindwoBar->minButton());
    agent->setSystemButton(QWK::WindowAgentBase::Maximize, m_pWindwoBar->maxButton());
    agent->setSystemButton(QWK::WindowAgentBase::Close, m_pWindwoBar->closeButton());

    agent->setHitTestVisible(m_pWindwoBar->menuBar(), true);

    ui->setupUi(this);
}

The code crashes at this line:
QWK::WidgetWindowAgent* agent = new QWK::WidgetWindowAgent(this);

The crash occurs in a thread checking function inside QObject

// check the constructor's parent thread argument
static bool check_parent_thread(QObject *parent,
                                QThreadData *parentThreadData,
                                QThreadData *currentThreadData)
{
    if (parent && parentThreadData != currentThreadData) {
        QThread *parentThread = parentThreadData->thread.loadAcquire();
        QThread *currentThread = currentThreadData->thread.loadAcquire();
        qWarning("QObject: Cannot create children for a parent that is in a different thread.\n"
                 "(Parent is %s(%p), parent's thread is %s(%p), current thread is %s(%p)",
                 parent->metaObject()->className(),
                 parent,
                 parentThread ? parentThread->metaObject()->className() : "QThread",
                 parentThread,
                 currentThread ? currentThread->metaObject()->className() : "QThread",
                 currentThread);
        return false;
    }
    return true;
}

this is my main.cpp

int main(int argc, char *argv[])
{
    QGuiApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);

    QApplication a(argc, argv);
    CMainUI w;
    w.show();

    return a.exec();
}

The command I used when building/compiling QWindowKit is:
cmake -B build -S .
cmake --build build --config Release
cmake --install install .

If I remove the this pointer in the constructor, it doesn't crash, but then the frameless window feature doesn't work.
I cannot get the specific stack trace. My environment is Qt 6.9 + MSVC2022 + Win11, CMake version 3.29.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions