[vlc-commits] qt: add dummy program to test QApplication

Rémi Denis-Courmont git at videolan.org
Thu Feb 8 23:16:16 CET 2018


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Feb  7 23:00:55 2018 +0200| [63599c0a54a15e53bd59de212cc0954faa2d1a64] | committer: Rémi Denis-Courmont

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.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=63599c0a54a15e53bd59de212cc0954faa2d1a64
---

 modules/Makefile.am             |  1 +
 modules/gui/qt/Makefile.am      |  7 +++++++
 modules/gui/qt/vlc-qt-check.cpp | 30 ++++++++++++++++++++++++++++++
 3 files changed, 38 insertions(+)

diff --git a/modules/Makefile.am b/modules/Makefile.am
index 53b90a2713..5e2151a051 100644
--- a/modules/Makefile.am
+++ b/modules/Makefile.am
@@ -3,6 +3,7 @@ check_LTLIBRARIES =
 pkglib_LTLIBRARIES =
 noinst_HEADERS =
 check_PROGRAMS =
+pkglibexec_PROGRAMS =
 EXTRA_DIST =
 
 EXTRA_SUBDIRS = \
diff --git a/modules/gui/qt/Makefile.am b/modules/gui/qt/Makefile.am
index cb77b14d96..a48677be92 100644
--- a/modules/gui/qt/Makefile.am
+++ b/modules/gui/qt/Makefile.am
@@ -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
diff --git a/modules/gui/qt/vlc-qt-check.cpp b/modules/gui/qt/vlc-qt-check.cpp
new file mode 100644
index 0000000000..685238c88b
--- /dev/null
+++ b/modules/gui/qt/vlc-qt-check.cpp
@@ -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);
+}



More information about the vlc-commits mailing list