linuxdeepin / dtk

Portal of DTK documentations
https://linuxdeepin.github.io/dtk/
Other
27 stars 15 forks source link

2023年9月15日 git clone 的版本启用dxcb崩溃 #128

Open yunhai2009 opened 1 year ago

yunhai2009 commented 1 year ago

SUMMARY | 问题概要

在DApplication a(argc,argv)之前调用DApplication::loadDXcbPlugin(),显示出来的窗口是无边框窗口,点击titlebar后崩溃。 崩溃信息在Dtk::Widget::DApplication::notify

DTK and OS VERSIONS | DTK&系统版本信息

dtkcore:5.6.12 qt:5.15.10

Minimal Reproducible Case Code | 最小复现案例代码

#include <DApplication>
#include <DMainWindow>
#include <DWidgetUtil>
#include <DApplicationSettings>
#include <DTitlebar>
#include <DProgressBar>
#include <DFontSizeManager>

#include <QPropertyAnimation>
#include <QDate>
#include <QLayout>
#include <QDebug>
DWIDGET_USE_NAMESPACE

int main(int argc, char *argv[])
{
    QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
    DApplication::loadDXcbPlugin();  //让bar处在标题栏中
    DApplication a(argc, argv);
    a.setOrganizationName("deepin");
    a.setApplicationName("dtk-application");
    a.setApplicationVersion("1.0");
    a.setProductIcon(QIcon(":/images/logo.svg"));
    a.setProductName("Dtk Application");
    a.setApplicationDescription("This is a dtk template application.");

    a.loadTranslator();
    a.setApplicationDisplayName(QCoreApplication::translate("Main", "DTK Application"));

    // 保存程序的窗口主题设置
    DApplicationSettings as;
    Q_UNUSED(as)

    DMainWindow w;
    qDebug()<< w.isDXcbWindow();
    w.titlebar()->setIcon(QIcon(":/images/logo.svg"));
    w.titlebar()->setTitle("Hello dtk");
    // 设置标题,宽度不够会隐藏标题文字
    w.setMinimumSize(QSize(600, 200));

    QWidget *cw = new QWidget(&w);
    QVBoxLayout *layout = new QVBoxLayout(cw);
    QDate today = QDate::currentDate();
    DProgressBar *yearProgressBar = new DProgressBar();
    yearProgressBar->setMaximum(today.daysInYear());
    // 绑定字体大小
    DFontSizeManager::instance()->bind(yearProgressBar, DFontSizeManager::T1);

    yearProgressBar->setAlignment(Qt::AlignCenter);
    QObject::connect(yearProgressBar, &DProgressBar::valueChanged, yearProgressBar, [yearProgressBar](int value){
        yearProgressBar->setFormat(QString("您的 %1 使用进度: %2%").arg(QDate::currentDate().year())
                                   .arg(value * 100 / yearProgressBar->maximum()));
    });

    layout->addWidget(yearProgressBar);
    w.setCentralWidget(cw);
    w.show();

    auto animation = new QPropertyAnimation(yearProgressBar, "value");
    animation->setDuration(5000);
    animation->setStartValue(0);
    animation->setEndValue(today.dayOfYear());
    animation->start();

    Dtk::Widget::moveToCenter(&w);

    return a.exec();
}

OBSERVED RESULT | 观察到的结果

崩溃,不启用DApplication::loadDXcbPlugin(); 就没有问题

EXPECTED RESULT | 期望的结果

No response

ADDITIONAL INFORMATION | 额外补充

qtcreator的调用堆栈 2023-09-15_16-51-32

BLumia commented 1 year ago

你的系统环境是什么,是 deepin 发行版吗?是的话,是v23还是20?

2023年9月15日 git clone 的版本

其实贴 commit hash 更有用一些