Tk-desktop post QApplication hook

I’ve set up a framework that gets initialised from an app configured in the project environment. This framework adds a few commands.

I have a method on the framework that I want to run when tk-desktop starts up. The method sets up a QThread and some QTimers.

When I run my meth in the framework init then it fails because the QApplication has not been set up yet. I had a look through the bootstrap code and it seems that the QApplication is only setup after the init. I can’t find any hooks that run after the QApplication has been set up.

My workaround at the moment is to fork the tk-desktop and add a post_qt_init hook (similar to tk-photoshopcc) that runs after the QApplication. I then use this hook in the shotgun_config to call my framework method. This works but I don’t really want to have to fork the app.

I think I could also fork the site config and implement the launch_python.py to change the path_to_boostrap to a custom bootstrap that calls my code after utiltities.start_app. However I’m not too keen on overriding the site config as that will require a site wide change as apposed to a project pipeline config change.

Is there any easier way of doing this?

4 Likes

Hi Jared!

I’m surprised that we create QApplication after the engine has been fully initialized. The right fix on our end would be to initialize it before apps and frameworks are loaded so you can access it during initialization. I’m cautiously optimistic that you could probably move the QApplication instantiation (and the instantiation only, not the rest of the code from _initialize_application) to the pre_app_init method on the DesktopEngineProjectImplementation class. You’ll need to make sure that the pre_app_init from the engine class is properly forwarded to the implementation class just like we did for post_app_init

Our hands are full right now, but if you’re willing you can send us a pull request with the suggested fix and we’ll QA when we’re ready. I wouldn’t consider the hook approach to be the appropriate fix at this moment.

JF

4 Likes

Thanks @jfboismenu, much appreciated! I’ll have a look at that when I get a chance.

2 Likes

Any news on this? It seems that Application.post_engine_init has still QApplication.instance() == None