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,

harsszegi
  • 369
  • 2
  • 15
  • 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? – cmannett85 Feb 05 '15 at 08:30
  • This has already been reported as a bug and closed : https://bugreports.qt.io/browse/QTBUG-22610 – Nejat Feb 05 '15 at 08:48
  • Also this post is similar : http://stackoverflow.com/questions/7929981/qgraphicssceneqgraphicsscene-segmentation-fault – Nejat Feb 05 '15 at 08:49
  • @cmannett85 I agree with that, but what would you do with a _scene_ in a cli application? –  Feb 05 '15 at 09:43
  • 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. –  Feb 05 '15 at 09:48
  • @Nejat not the same issue. that bug is due to the fact that the scene has a bigger lifespan than the QCoreApplication object. – UmNyobe Feb 05 '15 at 10:31
  • 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...) – harsszegi Feb 05 '15 at 12:12

1 Answers1

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"));

harsszegi
  • 369
  • 2
  • 15