簡體   English   中英

QPainter :: begin在調試模式下使程序崩潰

[英]QPainter::begin crashes the program in debug mode

1.問題描述

當程序正常運行時,調用QPainter :: begin可以正常工作,但是在調試模式下執行時,導致崩潰。 任何想法是什么原因?


2.環境

  • Windows 7 Pro 64位
  • Qt 5.9.2
  • MSVC 2017
  • Windows套件\\ 10 \\ Debuggers \\ x64 \\ cdb.exe

3.示例代碼

MainWindow.h

#include <QMainWindow>

class MainWindow : public QMainWindow
{
    Q_OBJECT
public:
    explicit MainWindow(QWidget *parent = nullptr);
};

MainWindow.cpp

#include "MainWindow.h"
#include "Painter.h"
#include <QLabel>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent)
{
    auto *label = new QLabel(this);

    label->setPixmap(Painter().paint());

    setCentralWidget(label);
}

畫家

#include <QObject>

class Painter : public QObject
{
    Q_OBJECT
public:
    explicit Painter(QObject *parent = nullptr);

    QPixmap paint();
};

Painter.cpp

#include "Painter.h"
#include <QPainter>

Painter::Painter(QObject *parent) : QObject(parent)
{

}

QPixmap Painter::paint()
{
    QPainter painter;
    QPixmap pixmap(16, 16);

    pixmap.fill(Qt::transparent);

    painter.begin(&pixmap); // <-- program crashes here on Debug

    return pixmap;
}

4.調試器的輸出

在此處輸入圖片說明 在此處輸入圖片說明

從bugreports.qt.io/browse/QTBUG-64581重新發布

如果您開始使用QPainter :: begin()進行繪制,則可以期望在完成繪制之前已通過QPaintDevice並且QPaintEngine仍處於活動狀態。 繪畫處於活動狀態(不調用end())時,請勿破壞QPaintEngine。 在示例中,QPixmap在QPainter完成繪制之前已銷毀。 需要先調用end()或確保像素圖還處於活動狀態。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM