Fix buggy Qt5 style detection causing segfault on Arch Linux w/ qt5-style-plugins qt5transition
authorWuzzy <Wuzzy2@mail.ru>
Tue, 13 Mar 2018 16:38:48 +0100
branchqt5transition
changeset 13185 3961f9d0c7e4
parent 13184 ddfb4a73524b
child 13186 2148b493836e
Fix buggy Qt5 style detection causing segfault on Arch Linux w/ qt5-style-plugins
QTfrontend/main.cpp
--- a/QTfrontend/main.cpp	Tue Mar 13 10:20:41 2018 -0400
+++ b/QTfrontend/main.cpp	Tue Mar 13 16:38:48 2018 +0100
@@ -155,11 +155,29 @@
 }
 
 int main(int argc, char *argv[]) {
-	/* Qt5 removed motif, plastique.  These are now in qt5-style-plugins which was NOT backported by debian/ubuntu to stable/LTS - windows appears to render best of the remaining options but still isn't quite right. */
-	// set windows initially
-	QApplication::setStyle(QStyleFactory::create("windows"));
-	// try setting plastique if available from qt5-style-plugins - in testing qt5 skips the call on fail to locate which leaves us on windows
-	QApplication::setStyle(QStyleFactory::create("plastique"));
+    /* Qt5 Base removed Motif, Plastique. These are now in the Qt style plugins
+    (Ubuntu: qt5-style-plugins, which was NOT backported by Debian/Ubuntu to stable/LTS).
+    Windows appears to render best of the remaining options but still isn't quite right. */
+
+    // Try setting Plastique if available
+    QStyle* coreStyle;
+    coreStyle = QStyleFactory::create("Plastique");
+    if(coreStyle != 0) {
+        QApplication::setStyle(coreStyle);
+        qDebug("Qt style set: Plastique");
+    } else {
+        // Use Windows as fallback.
+        // FIXME: Under Windows style, some widgets like scrollbars don't render as nicely
+        coreStyle = QStyleFactory::create("Windows");
+        if(coreStyle != 0) {
+            QApplication::setStyle(coreStyle);
+            qDebug("Qt style set: Windows");
+        } else {
+            // Windows style should not be missing in Qt5 Base. If it does, something went terribly wrong!
+            qWarning("No Qt style could be set! Using the default one.");
+        }
+    }
+
     // Since we're calling this first, closeResources() will be the last thing called after main() returns.
     atexit(closeResources);