JUCE: JUCEApplication Class Reference

JUCE

- Main Page
- Related Pages
- Modules
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
JUCEApplication Class Referenceabstract
juce_gui_basics » application

An instance of this class is used to specify initialisation and shutdown code for the application. More...

`#include <juce_Application.h>`

Inheritance diagram for JUCEApplication:

## Public Member Functions
| JUCEApplication ()
| Constructs a JUCE app object.
| ~JUCEApplication () override
| Destructor.
virtual const String | getApplicationName ()=0
| Returns the application's name.
virtual const String | getApplicationVersion ()=0
| Returns the application's version number.
bool | moreThanOneInstanceAllowed () override
| Checks whether multiple instances of the app are allowed.
void | anotherInstanceStarted (const String &commandLine) override
| Indicates that the user has tried to start up another instance of the app.
void | systemRequestedQuit () override
| Called when the operating system is trying to close the application.
void | suspended () override
| This method is called when the application is being put into background mode by the operating system.
void | resumed () override
| This method is called when the application is being woken from background mode by the operating system.
void | unhandledException (const std::exception *e, const String &sourceFilename, int lineNumber) override
| 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.
ApplicationCommandTarget * | getNextCommandTarget () override
| This must return the next target to try after this one.
void | getCommandInfo (CommandID, ApplicationCommandInfo &) override
| This must provide details about one of the commands that this target can perform.
void | getAllCommands (Array< CommandID > &) override
| This must return a complete list of commands that this target can handle.
bool | perform (const InvocationInfo &) override
| This must actually perform the specified command.
Public Member Functions inherited from JUCEApplicationBase
virtual | ~JUCEApplicationBase ()
| Destructor.
virtual const String | getApplicationName ()=0
| Returns the application's name.
virtual const String | getApplicationVersion ()=0
| Returns the application's version number.
virtual bool | moreThanOneInstanceAllowed ()=0
| Checks whether multiple instances of the app are allowed.
virtual void | initialise (const String &commandLineParameters)=0
| Called when the application starts.
virtual void | shutdown ()=0
virtual void | anotherInstanceStarted (const String &commandLine)=0
| Indicates that the user has tried to start up another instance of the app.
virtual void | systemRequestedQuit ()=0
| Called when the operating system is trying to close the application.
virtual void | suspended ()=0
| This method is called when the application is being put into background mode by the operating system.
virtual void | resumed ()=0
| This method is called when the application is being woken from background mode by the operating system.
virtual void | unhandledException (const std::exception *, const String &sourceFilename, int lineNumber)=0
| 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.
virtual void | memoryWarningReceived ()
| Called by the operating system to indicate that you should reduce your memory footprint.
virtual bool | backButtonPressed ()
| This will be called when the back button on a device is pressed.
void | setApplicationReturnValue (int newReturnValue) noexcept
| Sets the value that should be returned as the application's exit code when the app quits.
int | getApplicationReturnValue () const noexcept
| Returns the value that has been set as the application's exit code.
bool | isInitialising () const noexcept
| Returns true if the application hasn't yet completed its initialise() method and entered the main event loop.
Public Member Functions inherited from ApplicationCommandTarget
| ApplicationCommandTarget ()
| Creates a command target.
virtual | ~ApplicationCommandTarget ()
| Destructor.
virtual ApplicationCommandTarget * | getNextCommandTarget ()=0
| This must return the next target to try after this one.
virtual void | getAllCommands (Array< CommandID > &commands)=0
| This must return a complete list of commands that this target can handle.
virtual void | getCommandInfo (CommandID commandID, ApplicationCommandInfo &result)=0
| This must provide details about one of the commands that this target can perform.
virtual bool | perform (const InvocationInfo &info)=0
| This must actually perform the specified command.
bool | invoke (const InvocationInfo &invocationInfo, const bool asynchronously)
| Makes this target invoke a command.
bool | invokeDirectly (const CommandID commandID, const bool asynchronously)
| Invokes a given command directly on this target.
ApplicationCommandTarget * | getTargetForCommand (const CommandID commandID)
| Searches this target and all subsequent ones for the first one that can handle the specified command.
bool | isCommandActive (const CommandID commandID)
| Checks whether this command can currently be performed by this target.
ApplicationCommandTarget * | findFirstTargetParentComponent ()
| If this object is a Component, this method will search upwards in its current UI hierarchy for the next parent component that implements the ApplicationCommandTarget class.

## Static Public Member Functions
static JUCEApplication *JUCE_CALLTYPE | getInstance () noexcept
| Returns the global instance of the application object being run.
Static Public Member Functions inherited from JUCEApplicationBase
static JUCEApplicationBase * | getInstance () noexcept
| Returns the global instance of the application object that's running.
static void | quit ()
| Signals that the main message loop should stop and the application should terminate.
static StringArray JUCE_CALLTYPE | getCommandLineParameterArray ()
| Returns the application's command line parameters as a set of strings.
static String JUCE_CALLTYPE | getCommandLineParameters ()
| Returns the application's command line parameters as a single string.
static bool | isStandaloneApp () noexcept
| Returns true if this executable is running as an app (as opposed to being a plugin or other kind of shared library.

## Additional Inherited Members
Protected Member Functions inherited from JUCEApplicationBase
| JUCEApplicationBase ()

## Detailed Description

An instance of this class is used to specify initialisation and shutdown code for the application.

Any application that wants to run an event loop must declare a subclass of JUCEApplicationBase or JUCEApplication, 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.

Note that this class is derived from JUCEApplicationBase, which contains most of the useful methods and functionality. This derived class is here simply as a convenient way to also inherit from an ApplicationCommandTarget, and to implement default versions of some of the pure virtual base class methods. But you can derive your app object directly from JUCEApplicationBase if you want to, and by doing so can avoid having a dependency on the juce_gui_basics module.

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);
}
void shutdown() override
{
myMainWindow = nullptr;
}
const String getApplicationName() override
{
return "Super JUCE-o-matic";
}
const String getApplicationVersion() override
{
return "1.0";
}
private:
std::unique_ptr<MyApplicationWindow> myMainWindow;
};
// this generates boilerplate code to launch our app class:
START_JUCE_APPLICATION (MyJUCEApp)
JUCEApplication
An instance of this class is used to specify initialisation and shutdown code for the application.
Definition juce_Application.h:93
String
The JUCE String class!
Definition juce_String.h:54
START_JUCE_APPLICATION
#define START_JUCE_APPLICATION(AppClass)
To start a JUCE app, use this macro: START_JUCE_APPLICATION (AppSubClass) where AppSubClass is the na...
Definition juce_Initialisation.h:89

See also
  JUCEApplicationBase, START_JUCE_APPLICATION

## Constructor & Destructor Documentation

## ◆ JUCEApplication()

JUCEApplication::JUCEApplication | ( |  | ) |

Constructs a JUCE app object.

If subclasses implement a constructor or destructor, they shouldn't call any JUCE code in there - put your startup/shutdown code in initialise() and shutdown() instead.

## ◆ ~JUCEApplication()

JUCEApplication::~JUCEApplication | ( |  | ) |
| override

Destructor.

If subclasses implement a constructor or destructor, they shouldn't call any JUCE code in there - put your startup/shutdown code in initialise() and shutdown() instead.

## Member Function Documentation

## ◆ getInstance()

static JUCEApplication *JUCE_CALLTYPE JUCEApplication::getInstance | ( |  | ) |
| staticnoexcept

Returns the global instance of the application object being run.

## ◆ getApplicationName()

virtual const String JUCEApplication::getApplicationName | ( |  | ) |
| pure virtual

Returns the application's name.

Implements JUCEApplicationBase.

## ◆ getApplicationVersion()

virtual const String JUCEApplication::getApplicationVersion | ( |  | ) |
| pure virtual

Returns the application's version number.

Implements JUCEApplicationBase.

## ◆ moreThanOneInstanceAllowed()

bool JUCEApplication::moreThanOneInstanceAllowed | ( |  | ) |
| overridevirtual

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 OSX where the OS automatically stops you launching a second instance of an app without explicitly starting it from the command-line).

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.

Implements JUCEApplicationBase.

## ◆ anotherInstanceStarted()

void JUCEApplication::anotherInstanceStarted | ( | const String & | commandLine | ) |
| overridevirtual

Indicates that the user has tried to start up another instance of the app.

This will get called even if moreThanOneInstanceAllowed() is false.

Implements JUCEApplicationBase.

## ◆ systemRequestedQuit()

void JUCEApplication::systemRequestedQuit | ( |  | ) |
| overridevirtual

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.

Implements JUCEApplicationBase.

## ◆ suspended()

void JUCEApplication::suspended | ( |  | ) |
| overridevirtual

This method is called when the application is being put into background mode by the operating system.

Implements JUCEApplicationBase.

## ◆ resumed()

void JUCEApplication::resumed | ( |  | ) |
| overridevirtual

This method is called when the application is being woken from background mode by the operating system.

Implements JUCEApplicationBase.

## ◆ unhandledException()

void JUCEApplication::unhandledException | ( | const std::exception * | e,
|  | const String & | sourceFilename,
|  | int | lineNumber
| ) |  |
| overridevirtual

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.

Implements JUCEApplicationBase.

## ◆ getNextCommandTarget()

ApplicationCommandTarget * JUCEApplication::getNextCommandTarget | ( |  | ) |
| overridevirtual

This must return the next target to try after this one.

When a command is being sent, and the first target can't handle that command, this method is used to determine the next target that should be tried.

It may return nullptr if it doesn't know of another target.

If your target is a Component, you would usually use the findFirstTargetParentComponent() method to return a parent component that might want to handle it.

See also
  invoke

Implements ApplicationCommandTarget.

## ◆ getCommandInfo()

void JUCEApplication::getCommandInfo | ( | CommandID | commandID,
|  | ApplicationCommandInfo & | result
| ) |  |
| overridevirtual

This must provide details about one of the commands that this target can perform.

This will be called with one of the command IDs that the target provided in its getAllCommands() methods.

It should fill-in all appropriate fields of the ApplicationCommandInfo structure with suitable information about the command. (The commandID field will already have been filled-in by the caller).

The easiest way to set the info is using the ApplicationCommandInfo::setInfo() method to set all the fields at once.

If the command is currently inactive for some reason, this method must use ApplicationCommandInfo::setActive() to make that clear, (or it should set the isDisabled bit of the ApplicationCommandInfo::flags field).

Any default key-presses for the command should be appended to the ApplicationCommandInfo::defaultKeypresses field.

Note that if you change something that affects the status of the commands that would be returned by this method (e.g. something that makes some commands active or inactive), you should call ApplicationCommandManager::commandStatusChanged() to cause the manager to refresh its status.

Implements ApplicationCommandTarget.

## ◆ getAllCommands()

void JUCEApplication::getAllCommands | ( | Array< CommandID > & | commands | ) |
| overridevirtual

This must return a complete list of commands that this target can handle.

Your target should add all the command IDs that it handles to the array that is passed-in.

Implements ApplicationCommandTarget.

## ◆ perform()

bool JUCEApplication::perform | ( | const InvocationInfo & | info | ) |
| overridevirtual

This must actually perform the specified command.

If this target is able to perform the command specified by the commandID field of the InvocationInfo structure, then it should do so, and must return true.

If it can't handle this command, it should return false, which tells the caller to pass the command on to the next target in line.

See also
  invoke, ApplicationCommandManager::invoke

Implements ApplicationCommandTarget.

The documentation for this class was generated from the following file:

- juce_Application.h