[PySide] Application.type doesn't exist in PySide2 anymore

Frank Rueter | OHUfx frank at ohufx.com
Sun Mar 18 23:55:12 CET 2018


Thanks for clarifying, I thought I was missing something.

I am now doing this to check for GUI vs batch mode:

    if isinstance(QtWidgets.QApplication.instance(),
    QtWidgets.QApplication):
         # running in GUI mode


in batch mode QApplication is of type QCoreApplication, so the above 
seems to be the solution.

Cheers,
frank

On 19/03/18 6:32 AM, Alexandru Croitor wrote:
>
> Hi,
>
>
> There's no direct equivalent of qobject_cast in PySide2 afaik.
>
>
> Perhaps you can use the qApp macro, something like:
>
>
>  from PySide2.QtWidgets import QApplication
>
>  from PySide2 import QtCore
>
>  app = QApplication([])
>
>  if isinstance(QtCore.qApp, QApplication):
>
>   ....
>
>
> or alternatively type(QtCore.qApp).__name__ and then a string compare, 
> which avoids importing.
>
> Or some variation of the above.
>
>
> Note you might stumble on 
> https://bugreports.qt.io/browse/PYSIDE-585 due to qApp usage.
>
> ------------------------------------------------------------------------
> *From:* PySide <pyside-bounces+alexandru.croitor=qt.io at qt-project.org> 
> on behalf of Frank Rueter | OHUfx <frank at ohufx.com>
> *Sent:* Sunday, March 18, 2018 12:44:15 AM
> *To:* pyside at qt-project.org
> *Subject:* Re: [PySide] Application.type doesn't exist in PySide2 anymore
> I am finally getting back to this now.
> I can't find qobject_cast anywhere. I can only find the C++ example 
> <http://doc.qt.io/qt-5/qobject.html#qobject_cast> which confuses me a 
> bit though.
> Could somebody share an example how to check the application type in 
> PySide2 please?
>
> Cheers,
> frank
>
> On 11/12/17 12:20 PM, Frank Rueter | OHUfx wrote:
>> great, thank you, I will look into this...
>>
>>
>> On 11/12/17 10:58 AM, Alexey Vihorev wrote:
>>>
>>> http://doc.qt.io/qt-5/sourcebreaks.html
>>>
>>> ·|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.
>>>
>>> *От: *Frank Rueter | OHUfx <mailto:frank at ohufx.com>
>>> *Отправлено: *10 декабря 2017 г. в 23:53
>>> *Кому: *pyside at qt-project.org <mailto:pyside at qt-project.org>
>>> *Тема: *[PySide] Application.type doesn't exist in PySide2 anymore
>>>
>>> And another PySide2 migration question:
>>> I used to do this to check id an app is run in GUI or command line mode:
>>> if QtWidgets.QApplication.type() == 
>>> QtWidgets.QApplication.Type.GuiClient:
>>>     ...
>>>
>>> However QtWidgets.QApplication.type() doesn't exist in PySdie2 anymore.
>>> What's the best way to achieve the same goal?
>>>
>>> Thanks,
>>> frank
>>>
>>> -- 
>>>
>>> ohufxLogo 50x50 <http://www.ohufx.com>
>>>
>>> 	
>>> 	
>>>
>>> *vfx compositing <http://ohufx.com/compositing.html>**| **workflow 
>>> customisation and consulting <http://ohufx.com/customising.html> *
>>>
>>> 	
>>>
>>> 	
>>>
>>> http://nukepedia.com/images/nuBridge/logo/nuBridge_logo.png 
>>> <http://www.nukepedia.com/nubridge>
>>>
>>> 	
>>> 	
>>>
>>> Your gateway to over 1,000 free tools... right inside of Nuke 
>>> <http://www.nukepedia.com/nubridge>
>>>
>>
>>
>>
>> _______________________________________________
>> PySide mailing list
>> PySide at qt-project.org <mailto:PySide at qt-project.org>
>> http://lists.qt-project.org/mailman/listinfo/pyside
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20180319/73ce23ab/attachment.html>


More information about the PySide mailing list