Initialize JUCE GUI and startup event loop


Hi, i am having problems with my JUCE application. It works fine when i use the START_JUCE_APPLICATION macro, but sometimes i prefer to use function main() as my own startup event loop, so please show me example code for the initialiseJuce_GUI() function, as it isn’t working at the moment


You can easily go and look at the code where we implemented main() in the library, it’s only a few lines:

int JUCEApplicationBase::main()
    ScopedJuceInitialiser_GUI libraryInitialiser;
    jassert (createInstance != nullptr);

    const ScopedPointer<JUCEApplicationBase> app (createInstance());
    jassert (app != nullptr);

    if (! app->initialiseApp())
        return app->shutdownApp();

        // loop until a quit message is received..

    return app->shutdownApp();

But I’d really strongly recommend NOT to roll your own main() function for a GUI app unless you have a genuinely good reason not to use ours.

All the different OSes have different requirements and on Android and iOS there isn’t really a main() function at all. If you’re building a command-line app then sure, just call initialiseJuce_GUI() but running your own event loop will cause lots of pain. Good luck if you go down that route - we can’t really help you, you’ll need to figure out all the edge case problems yourself.


Thanks for the genuine advice sir esquire Jules. Please remember our future
request for multiple hardware interface support in JUCE modules API (USB
3+, blue tooth, RS232 etc)