title: How to check for gui vs command line mode in PySide2?
body: <p>in my PySide2 code I need to check if the program is run in gui mode or command line. In PySide I used to do this:</p>
  
  <pre><code>if QApplication.type() == QApplication.Type.GuiClient:
      # do stuff
  </code></pre>
  
  <p>However, as per <a href="http://doc.qt.io/qt-5/sourcebreaks.html" rel="nofollow noreferrer">http://doc.qt.io/qt-5/sourcebreaks.html</a>: </p>
  
  <blockquote>
    <p>QCoreApplication::Type and QApplication::type() are removed. These Qt
    3 legacy application types did not match the application types
    available in Qt 5. Use qobject_cast instead to dynamically find out
    the exact application type.</p>
  </blockquote>
  
  <p>My PySide program is running inside a host application, so I am not creating a QCoreApplication instance myself, I just need to check if the host application is in batch mode (non GUI) or not to avoid some issues.</p>
  
  <p>My question now is how to use <a href="http://doc.qt.io/qt-5/qobject.html#qobject_cast" rel="nofollow noreferrer">qobject_cast</a> to achieve the same in PySide2?
  The <a href="http://doc.qt.io/qt-5/qobject.html#qobject_cast" rel="nofollow noreferrer">C++ examples</a> in the docs doesn't tell me much how to go about this with Python.</p>
  
  <p>Could somebody please provide an example or advise on other ways to achieve the same thing?</p>