If no screens, attempting to create a window results in clean exit

Asserting is only relevant for debug builds, and there were a couple
of other places that a segfault would typically occur before the assert
had a chance.

Change-Id: I1abc82eb3ecfa91050117fab1525f4cbd82ff486
Task-number: QTBUG-37876
Reviewed-by: Andy Shaw <andy.shaw@digia.com>
Reviewed-by: Laszlo Agocs <laszlo.agocs@digia.com>
bb10
Shawn Rutledge 2014-03-28 08:12:05 +01:00 committed by The Qt Project
parent c5805acccd
commit 51d4eb8f5b
3 changed files with 15 additions and 5 deletions

View File

@ -64,6 +64,8 @@ QNativeImage::~QNativeImage()
QImage::Format QNativeImage::systemFormat()
{
if (!QGuiApplication::primaryScreen())
return QImage::Format_Invalid;
return QGuiApplication::primaryScreen()->handle()->format();
}

View File

@ -159,10 +159,6 @@ QWindow::QWindow(QScreen *targetScreen)
d->screen = targetScreen;
if (!d->screen)
d->screen = QGuiApplication::primaryScreen();
//if your applications aborts here, then chances are your creating a QWindow before the
//screen list is populated.
Q_ASSERT(d->screen);
d->init();
}
@ -232,6 +228,13 @@ QWindow::~QWindow()
void QWindowPrivate::init()
{
Q_Q(QWindow);
// If your application aborts here, you are probably creating a QWindow
// before the screen list is populated.
if (!screen) {
qFatal("Cannot create window: no screens available");
exit(1);
}
QObject::connect(screen, SIGNAL(destroyed(QObject*)), q, SLOT(screenDestroyed(QObject*)));
QGuiApplicationPrivate::window_list.prepend(q);
}

View File

@ -66,7 +66,12 @@ static QColormapPrivate *screenMap = 0;
void QColormap::initialize()
{
screenMap = new QColormapPrivate;
if (!QGuiApplication::primaryScreen()) {
qWarning("no screens available, assuming 24-bit color");
screenMap->depth = 24;
screenMap->mode = QColormap::Direct;
return;
}
screenMap->depth = QGuiApplication::primaryScreen()->depth();
if (screenMap->depth < 8) {
screenMap->mode = QColormap::Indexed;