Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-104801

Crash with QPainter::drawText used on a QQuickView with a Text item

    XMLWordPrintable

Details

    • Windows
    • 4fdadd2348 (qt/qtbase/dev) 4fdadd2348 (qt/tqtc-qtbase/dev) 7bc93fc70f (qt/qtbase/6.3) 40e8e9c55f (qt/qtbase/6.4) 7bc93fc70f (qt/tqtc-qtbase/6.3) 40e8e9c55f (qt/tqtc-qtbase/6.4)

    Description

      It crashes when using QPainter::drawText with a QOpenGLPaintDevice on a QQuickView which shows a Text Qml item.

      This one-file example shows the crash:

       

      #include <QtGui/QGuiApplication>
      #include <QtCore/QDebug>
      #include <QtCore/QTemporaryFile>
      #include <QtGui/QPainter>
      #include <QtQuick/QQuickView>
      #include <QtOpenGL/QOpenGLPaintDevice>
      #include <stdexcept>
      
      using namespace std;
      
      int main(int argc, char** argv)
      {
      	QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGL);
      	QGuiApplication app(argc, argv);
      	QQuickView view;
      	QOpenGLPaintDevice *device = nullptr;
      	QObject::connect(&view, &QQuickWindow::beforeSynchronizing, &view
      		,[&]
      		{
      			QObject::connect(&view, &QQuickWindow::beforeRenderPassRecording, &view
      				, [&]
      				{
      					view.beginExternalCommands();
      					if (!device) device = new QOpenGLPaintDevice();
      					device->setSize(QSize(view.width(), view.height()));
      					QPainter painter(device);
      					painter.setPen(Qt::blue);
      					painter.drawLine(0,0,50,50); // <-- This always works
      					painter.drawText(QPoint(30, 30), "Text_from_QPainter::drawText"); // <-- The crash occurs in this call to drawText, only if the Text qml element below is visible.
      					view.endExternalCommands();
      				}
      				, Qt::DirectConnection);
      		}
      		, Qt::DirectConnection);
      	QTemporaryFile temp_file_because_qquickview_doesnt_have_setRoot("XXXXXX.qml");
      	if(!temp_file_because_qquickview_doesnt_have_setRoot.open())
      	{
      		qCritical() << "Can't open a temporary file for writing the qml source to be loaded.";
      		return -1;
      	}
      	{
      		QTextStream stream(&temp_file_because_qquickview_doesnt_have_setRoot);
      		stream << QString(R"fin(
      				
      			import QtQuick 2.0
      			Text
      			{
      				//visible: false // <-- The crash only occurs if this text is visible.
      				color: 'blue'
      				text: "TextQml"
      			}
      				
      			)fin");
      	}
      	view.setSource(QUrl::fromLocalFile(temp_file_because_qquickview_doesnt_have_setRoot.fileName()));
      	view.show();
      	return app.exec();
      }
      
      #ifdef _DEBUG
      #pragma comment(lib,"Qt6Quickd.lib")
      #pragma comment(lib,"Qt6Guid.lib")
      #pragma comment(lib,"Qt6OpenGLd.lib")
      #pragma comment(lib,"Qt6Cored.lib")
      #pragma comment(lib,"Qt6Qmld.lib")
      #pragma comment(lib,"Qt6QuickWidgetsd.lib")
      #else
      #pragma comment(lib,"Qt6Quick.lib")
      #pragma comment(lib,"Qt6Gui.lib")
      #pragma comment(lib,"Qt6OpenGL.lib")
      #pragma comment(lib,"Qt6Core.lib")
      #pragma comment(lib,"Qt6Qml.lib")
      #pragma comment(lib,"Qt6QuickWidgets.lib")
      #endif
      
      

       

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            lagocs Laszlo Agocs
            domg Dominic Genest
            Votes:
            2 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes