Qt World Summit: Submit your Presentation

Qt GUI environment in a DLL

  • I would like to use the Qt GUI library as the user interface for a VST plugin. A VST plugin is a DLL on windows. A host application calls various functions on the DLL, including things like openGUI().

    I want to know how to use Qt GUI from a DLL; I have done some research to look at the possible options but I'm not completely sure on the limitations.

    The main problem is where to create the QApplication object and call exec() on it (which is a function that does not return until the application has quit).

    I have looked at the solution given in "this post":http://stackoverflow.com/questions/11054087/starting-qt-gui-from-dll-in-dllstart-function, but after further reading it would appear this solution will not work on Mac OS X, as Cocoa is more restrictive about the particular thread a GUI can run on. It's a bit of a hack really.

    I have also seen "this solution":http://stackoverflow.com/questions/1678937/dllmain-and-qt-mfc-migration, but that relies on QMfcApp and QWinWindow which don't appear to be part of the Qt library any more.

    Is the only way round this for my DLL to spawn off a new application itself? Presumably I could start one with a call to QProcess and use some shared memory to share between the GUI application and my VST DLL? Has anyone come across this type of problem? Am I going down a bad route with this or is there something I haven't thought of yet?

  • [quote author="oggmonster" date="1349855397"]I have also seen "this solution":http://stackoverflow.com/questions/1678937/dllmain-and-qt-mfc-migration, but that relies on QMfcApp and QWinWindow which don't appear to be part of the Qt library any more.[/quote] It has always been a separate utility.


  • I'd recommend to use Juce for VST or other plugins like RTAS, it has a project preset that builds statically linked dlls with no external dependencies.

  • Hmm, maybe trying to use Qt in this way isn't the best route then. It would just be really nice if I could use Qt GUI somehow because the library is so good.

  • Qt doesn't really have stock widgets that are suitable for a VST plugin such as dials, knobs, meters and so on... There are some addons for Qt that have such widgets but they mostly use OS specific styling, making them a little odd for use in VST plugins.

    You can still use Qt, you can still implement your own widgets, but Qt doesn't provide VST functionality out of the box, you have to use the Steinberg SDK or something similar, with Juce it is supported by the framework, and there are dozens of popular plugins that use the framework.

  • Yes I am aware that Qt doesn't support VST out of the box. I have created Qt Creator projects that compile against the VST SDK, that is not the issue.

    All of the components will be my own custom ones anyway, derived from QWidget. I find the Qt GUI library very comfortable to work with and that is why I want to use it in this way. Furthermore I like the Qt Core ibrary and am very familiar with it.

    The only problem I have got is in creating the event loop Qt needs to run from my plug-in. The fact it is a VST is irrelevant, I just want to work out how to use Qt GUI without having a main function that calls qApp->exec().

    It seems there is no simple way to do this that I can find, so Juce might be more appropriate like you say

  • The whole concept of QtGui revolves around the exec loop - event handling, signals and slots and such. It is the way the framework is designed to operate, I am not sure there is a workaround for this.

  • Did you look at the link I posted? From the qtsolutions/winmigrate help:

    @The Qt/MFC Migration Framework tool assists in the migration of existing Win32 or MFC applications to the Qt toolkit.

    The project provides a set of classes that allow using Qt and MFC/Win32 windows in the same application. User interface elements developed with Qt can be embedded into an existing MFC or Win32 based user interface, and existing custom controls developed with MFC or Win32 can be integrated into Qt widgets.@

  • @utcenter - Well I linked to 2 possible workarounds and suggested another in my original post. Just none of them are very clean, because Qt GUI wasn't designed with this in mind like you say. I was just curious to see if I was missing something, it would seem not and there is no simple way to achieve what I want

  • @blobfish - Yeh I've got a clone of that repository now, thanks for that. I'l give it a go later, looks promising for Windows. Not sure how to tackle Mac OS though

  • I tried only modal dialogs in my dll's on both windows and mac. Since modal dialogs use local event loop, it works. However if you want to create modeless dialogs or other widgets, maybe you can take a look to "QAbstractEventDispatcher":http://qt-project.org/doc/qt-4.8/qabstracteventdispatcher.html#details.

    bq. QAbstractEventDispatcher also allows the integration of an external event loop with the Qt event loop. For example, the Motif Extension includes a reimplementation of QAbstractEventDispatcher that merges Qt and Motif events together.

  • @cincirin - Cool, looks like a good lead. I wonder whether it's possible to use QAbstractEventDispatcher in the manner "described here":http://stackoverflow.com/questions/1051333/combing-an-external-event-loop-with-qts using another event loop (which I already have from the host application) to call processEvents()

  • Yes, maybe processEvents() will work. See "this Qt DLL in non Qt application forum":http://www.qtcentre.org/threads/14188-Qt-DLL-in-non-Qt-application Look at second post/solution proposed by @wysota :

    bq. call QApplication:rocessEvents() periodically instead. This is a hack, but it will work

  • This conversation jogged my thinking. Since the Qt framework requires you to buy a license in order to statically link to their libraries, this may be ... inconvenient at best. VST plugin users are used to having a single DLL in order for their plugin to work, although external impulses or other WAV files are also employed. You will need QtCore4.dll and QtGui4.dll, in addition to your main DLL in order to make a working plugin. I have no problem delivering a normal application with extra DLL's, as most users won't care, but VST users don't usually expect their plugin consisting of three or more DLL's - especially if you're doing a fairly simple effect. Of course, you could pay for the commercial version.

Log in to reply