qt: add dummy program to test QApplication

The QApplication constructor exits the entire process if it cannot find
a working Qt back-end. This is unacceptable within VLC, as we expect to
fallback to another interface plugin in such circumstances.

Qt 4.x selected its back-end at build time. VLC would try to connect to
the same back-end system (in practice: X11) to second-guess
QApplication, and preempt the initialization failure.

Qt 5.x selects its back-end at run time depending on installed back-end
plugins and running windowing system(s). There are no reasonable and
reliable ways to second-guess Qt anymore.

This commit introduces a dummy executable program that simply tries to
instantiate a QApplication. If it succeeds, it returns 0. Otherwise, it
returns an error. This allows its parent process to safely check if Qt
is available at run-time.
This commit is contained in:
Rémi Denis-Courmont 2018-02-07 23:00:55 +02:00
parent ae6ecfb36e
commit 63599c0a54
3 changed files with 38 additions and 0 deletions

View File

@ -3,6 +3,7 @@ check_LTLIBRARIES =
pkglib_LTLIBRARIES =
noinst_HEADERS =
check_PROGRAMS =
pkglibexec_PROGRAMS =
EXTRA_DIST =
EXTRA_SUBDIRS = \

View File

@ -448,7 +448,14 @@ nodist_libqt_plugin_la_SOURCES += gui/qt/resources.cpp
gui/qt/resources.cpp: gui/qt/vlc.qrc $(libqt_plugin_la_RES)
$(AM_V_GEN)$(RCC) -name vlc -o $@ $<
vlc_qt_check_SOURCES = gui/qt/vlc-qt-check.cpp
vlc_qt_check_CXXFLAGS = $(AM_CXXFLAGS) $(QT_CFLAGS) -fPIC
vlc_qt_check_LDADD = $(QT_LIBS)
if ENABLE_QT
gui_LTLIBRARIES += libqt_plugin.la
BUILT_SOURCES += $(nodist_libqt_plugin_la_SOURCES)
if !HAVE_WIN32
pkglibexec_PROGRAMS += vlc-qt-check
endif
endif

View File

@ -0,0 +1,30 @@
/*****************************************************************************
* vlc-qt-check.cpp: run-time Qt availability test
****************************************************************************
* Copyright © 2018 Rémi Denis-Courmont
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
}