Abstract base class for application classes.
Note that in the juce_gui_basics module, there's a utility class JUCEApplication which derives from JUCEApplicationBase, and takes care of a few chores. Most of the time you'll want to derive your class from JUCEApplication rather than using JUCEApplicationBase directly, but if you're not using the juce_gui_basics module then you might need to go straight to this base class.
Any application that wants to run an event loop must declare a subclass of JUCEApplicationBase, and implement its various pure virtual methods.
It then needs to use the START_JUCE_APPLICATION macro somewhere in a CPP file to declare an instance of this class and generate suitable platform-specific boilerplate code to launch the app.
e.g.
class MyJUCEApp : public JUCEApplication
{
public:
MyJUCEApp() {}
~MyJUCEApp() {}
void initialise (
const String& commandLine)
override
{
myMainWindow.reset (new MyApplicationWindow());
myMainWindow->setBounds (100, 100, 400, 500);
myMainWindow->setVisible (true);
}
{
myMainWindow = nullptr;
}
{
return "Super JUCE-o-matic";
}
{
return "1.0";
}
private:
std::unique_ptr<MyApplicationWindow> myMainWindow;
};
- See also
- JUCEApplication, START_JUCE_APPLICATION
@tags{Events}
virtual bool juce::JUCEApplicationBase::backButtonPressed |
( |
| ) |
|
|
inlinevirtual |
This will be called when the back button on a device is pressed.
The return value should be used to indicate whether the back button event has been handled by the application, for example if you want to implement custom navigation instead of the standard behaviour on Android.
This is currently only implemented on Android devices.
- Returns
- true if the event has been handled, or false if the default OS behaviour should happen
virtual void juce::JUCEApplicationBase::initialise |
( |
const String & |
commandLineParameters | ) |
|
|
pure virtual |
Called when the application starts.
This will be called once to let the application do whatever initialisation it needs, create its windows, etc.
After the method returns, the normal event-dispatch loop will be run, until the quit() method is called, at which point the shutdown() method will be called to let the application clear up anything it needs to delete.
If during the initialise() method, the application decides not to start-up after all, it can just call the quit() method and the event loop won't be run.
- Parameters
-
- See also
- shutdown, quit
virtual bool juce::JUCEApplicationBase::moreThanOneInstanceAllowed |
( |
| ) |
|
|
pure virtual |
Checks whether multiple instances of the app are allowed.
If your application class returns true for this, more than one instance is permitted to run (except on the Mac where this isn't possible).
If it's false, the second instance won't start, but you will still get a callback to anotherInstanceStarted() to tell you about this - which gives you a chance to react to what the user was trying to do.
- See also
- anotherInstanceStarted
Implemented in juce::JUCEApplication.
static void juce::JUCEApplicationBase::quit |
( |
| ) |
|
|
static |
Signals that the main message loop should stop and the application should terminate.
This isn't synchronous, it just posts a quit message to the main queue, and when this message arrives, the message loop will stop, the shutdown() method will be called, and the app will exit.
Note that this will cause an unconditional quit to happen, so if you need an extra level before this, e.g. to give the user the chance to save their work and maybe cancel the quit, you'll need to handle this in the systemRequestedQuit() method - see that method's help for more info.
- See also
- MessageManager
Referenced by juce::StandaloneFilterWindow::closeButtonPressed().
virtual void juce::JUCEApplicationBase::systemRequestedQuit |
( |
| ) |
|
|
pure virtual |
Called when the operating system is trying to close the application.
The default implementation of this method is to call quit(), but it may be overloaded to ignore the request or do some other special behaviour instead. For example, you might want to offer the user the chance to save their changes before quitting, and give them the chance to cancel.
If you want to send a quit signal to your app, this is the correct method to call, because it means that requests that come from the system get handled in the same way as those from your own application code. So e.g. you'd call this method from a "quit" item on a menu bar.
Implemented in juce::JUCEApplication.
virtual void juce::JUCEApplicationBase::unhandledException |
( |
const std::exception * |
, |
|
|
const String & |
sourceFilename, |
|
|
int |
lineNumber |
|
) |
| |
|
pure virtual |
If any unhandled exceptions make it through to the message dispatch loop, this callback will be triggered, in case you want to log them or do some other type of error-handling.
If the type of exception is derived from the std::exception class, the pointer passed-in will be valid. If the exception is of unknown type, this pointer will be null.
Implemented in juce::JUCEApplication.