How to use QGraphicsScene in console application?
Asked Answered
K

1

7

according to the Qt specification QGraphicsScene is a viewless data model of QGraphicsItems. I have a tool which can be used in windowed and in non-windowed mode (when providing commandline arguments to it). In non windowed mode it should run as a console application (e.g. not connecting to X or so). However either I use the application as a QCoreApplication (qt5) or I set the guienabled flag (qt4) to false in QApplication my application (obviously?) crashes when trying to instantiate the QGraphicsScene object.

Any idea how to use QGraphicsScene in a console application (apart from "no, you can't")? Thanks,

Kittykitwe answered 5/2, 2015 at 7:32 Comment(7)
Upvote from me, at first I thought this was a stupid question as QGraphicsScene is in the widgets library so I assumed it must need QPainter - but there's nothing in the API or docs that states it must be able to render anything. What does your debugger say when it crashes?Izmir
This has already been reported as a bug and closed : bugreports.qt.io/browse/QTBUG-22610Fluellen
Also this post is similar : #7930481Fluellen
@Izmir I agree with that, but what would you do with a scene in a cli application?Storytelling
I'm not saying "no, you can't." Maybe you can, I don't know that. But what's the point? It's a graphics scene. It's useless without any graphics.Storytelling
@Fluellen not the same issue. that bug is due to the fact that the scene has a bigger lifespan than the QCoreApplication object.Clavus
QGraphicsScene is not a "scene", it doesn't display anything, it's a data model. QGraphicsView is the one who displays your data model. That is why I need to have a colution to use the data model without rendering. Also the funny thing is that it crashes during the construction of the QGraphicsScene (guess it tries to link to the gui api queue...)Kittykitwe
K
1

If anybody is interested in it, there is a solution in Qt5. Just put this before instantiating QApplication

qputenv("QT_QPA_PLATFORM", QByteArrayLiteral("minimal"));

Kittykitwe answered 6/2, 2015 at 5:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.