I've been experimenting with using Qt in DFHack plugins and it's mostly working (much better that I thought it would at first).
There is no issue that I could see on Windows. On Linux, it crashes on exit when SDL tries to clean up some X11 related resources. I understand it is an issue from Xlib no supporting concurrency. It can be fixed by using Wayland backend for the Qt part, or by replacing SDL 1.2 with SDL2 thanks to
sdlcl (I guess the newer
sdl12-compat would work too). I did not test with macOS.
I pushed the code on
this github. The qapplication plugin manages the main Qt thread and provides a few basic commands for configuration or diagnostics. Other plugins can call addTopLevelWidget from include/TopLevelWidget.h to create widgets. qapplication needs to be enabled before Qt widgets can be created.
The
labors branch contains a very basic DT-like plugin that can serve as a demo. If you want to try it you will need to have the
default_gridviews.dtg file from DT copied in DF root directory. Data is only accessed when the game is suspended (use the "suspend" and "resume" buttons in the tool bar).
Multi-threading make such plugins a little difficult to write since you need to either suspend the game or copy all the data you need. But I think it is still easier than external applications since you can take advantage of all DFHack helper functions and you would need to copy the data anyway in an external application.
I currently only access/modify DF data when a CoreSuspender is locked, but I wonder if this could be relaxed. Can any assumption be made on some pointers validity with regards to state change events (SC_WORLD_LOADED, SC_WORLD_UNLOADED, SC_MAP_LOADED, SC_MAP_UNLOADED, SC_PAUSED, SC_UNPAUSED, ...) for read-only access?