Inherited by: QApplication
The PySide.QtCore.QCoreApplication class provides an event loop for console Qt applications.
This class is used by non-GUI applications to provide their event loop. For non-GUI application that uses Qt, there should be exactly one PySide.QtCore.QCoreApplication object. For GUI applications, see PySide.QtGui.QApplication .
PySide.QtCore.QCoreApplication contains the main event loop, where all events from the operating system (e.g., timer and network events) and other sources are processed and dispatched. It also handles the application’s initialization and finalization, as well as system-wide and application-wide settings.
The event loop is started with a call to exec() . Long running operations can call PySide.QtCore.QCoreApplication.processEvents() to keep the application responsive.
In general, we recommend that you create a PySide.QtCore.QCoreApplication or a PySide.QtGui.QApplication object in your main() function as early as possible. PySide.QtCore.QCoreApplication.exit() will not return until the event loop exits; e.g., when PySide.QtCore.QCoreApplication.quit() is called.
Several static convenience functions are also provided. The PySide.QtCore.QCoreApplication object is available from PySide.QtCore.QCoreApplication.instance() . Events can be sent or posted using PySide.QtCore.QCoreApplication.sendEvent() , PySide.QtCore.QCoreApplication.postEvent() , and PySide.QtCore.QCoreApplication.sendPostedEvents() . Pending events can be removed with PySide.QtCore.QCoreApplication.removePostedEvents() or flushed with PySide.QtCore.QCoreApplication.flush() .
The class provides a PySide.QtCore.QCoreApplication.quit() slot and an PySide.QtCore.QCoreApplication.aboutToQuit() signal.
An application has an PySide.QtCore.QCoreApplication.applicationDirPath() and an PySide.QtCore.QCoreApplication.applicationFilePath() . Library paths (see QLibrary ) can be retrieved with PySide.QtCore.QCoreApplication.libraryPaths() and manipulated by PySide.QtCore.QCoreApplication.setLibraryPaths() , PySide.QtCore.QCoreApplication.addLibraryPath() , and PySide.QtCore.QCoreApplication.removeLibraryPath() .
Translation files can be added or removed using PySide.QtCore.QCoreApplication.installTranslator() and PySide.QtCore.QCoreApplication.removeTranslator() . Application strings can be translated using PySide.QtCore.QCoreApplication.translate() . The QObject.tr() and QObject.trUtf8() functions are implemented in terms of PySide.QtCore.QCoreApplication.translate() .
The command line arguments which are passed to PySide.QtCore.QCoreApplication ‘s constructor should be accessed using the PySide.QtCore.QCoreApplication.arguments() function. Note that some arguments supplied by the user may have been processed and removed by PySide.QtCore.QCoreApplication .
In cases where command line arguments need to be obtained using the PySide.QtCore.QCoreApplication.argv() function, you must convert them from the local string encoding using QString.fromLocal8Bit() .
On Unix/Linux Qt is configured to use the system locale settings by default. This can cause a conflict when using POSIX functions, for instance, when converting between data types such as floats and strings, since the notation may differ between locales. To get around this problem, call the POSIX function setlocale(LC_NUMERIC,"C") right after initializing PySide.QtGui.QApplication or PySide.QtCore.QCoreApplication to reset the locale that is used for number formatting to “C”-locale.
See also
PySide.QtGui.QApplication PySide.QtCore.QAbstractEventDispatcher PySide.QtCore.QEventLoop Semaphores Example Wait Conditions Example
Parameters: | arg__1 – PySequence |
---|
This enum type defines the 8-bit encoding of character string arguments to PySide.QtCore.QCoreApplication.translate() :
Constant | Description |
---|---|
QCoreApplication.CodecForTr | The encoding specified by QTextCodec.codecForTr() (Latin-1 if none has been set). |
QCoreApplication.UnicodeUTF8 | UTF-8. |
QCoreApplication.DefaultCodec | (Obsolete) Use CodecForTr instead. |
See also
QObject.tr() QObject.trUtf8() QString.fromUtf8()
Parameters: | arg__1 – unicode |
---|
Prepends path to the beginning of the library path list, ensuring that it is searched for libraries first. If path is empty or already in the path list, the path list is not changed.
The default path list consists of a single entry, the installation directory for plugins. The default installation directory for plugins is INSTALL/plugins , where INSTALL is the directory where Qt was installed.
In Symbian this function is only useful for adding paths for finding Qt extension plugin stubs, since the OS can only load libraries from the /sys/bin directory.
Return type: | unicode |
---|
Returns the directory that contains the application executable.
For example, if you have installed Qt in the C:\Trolltech\Qt directory, and you run the regexp example, this function will return “C:/Trolltech/Qt/examples/tools/regexp”.
On Mac OS X this will point to the directory actually containing the executable, which may be inside of an application bundle (if the application is bundled).
Warning
On Linux, this function will try to get the path from the /proc file system. If that fails, it assumes that argv[0] contains the absolute file name of the executable. The function also assumes that the current directory has not been changed by the application.
In Symbian this function will return the application private directory, not the path to executable itself, as those are always in /sys/bin . If the application is in a read only drive, i.e. ROM, then the private path on the system drive will be returned.
Return type: | unicode |
---|
Returns the file path of the application executable.
For example, if you have installed Qt in the /usr/local/qt directory, and you run the regexp example, this function will return “/usr/local/qt/examples/tools/regexp/regexp”.
Warning
On Linux, this function will try to get the path from the /proc file system. If that fails, it assumes that argv[0] contains the absolute file name of the executable. The function also assumes that the current directory has not been changed by the application.
Return type: | unicode |
---|
This property holds the name of this application.
The value is used by the PySide.QtCore.QSettings class when it is constructed using the empty constructor. This saves having to repeat this information each time a PySide.QtCore.QSettings object is created.
Return type: | PySide.QtCore.qint64 |
---|
Returns the current process ID for the application.
Return type: | unicode |
---|
This property holds the version of this application.
Return type: | list of strings |
---|
Returns the list of command-line arguments.
Usually PySide.QtCore.QCoreApplication.arguments() .at(0) is the program name, PySide.QtCore.QCoreApplication.arguments() .at(1) is the first argument, and PySide.QtCore.QCoreApplication.arguments() . last() is the last argument. See the note below about Windows.
Calling this function is slow - you should store the result in a variable when parsing the command line.
Warning
On Unix, this list is built from the argc and argv parameters passed to the constructor in the main() function. The string-data in argv is interpreted using QString.fromLocal8Bit() ; hence it is not possible to pass, for example, Japanese command line arguments on a system that runs in a Latin1 locale. Most modern Unix systems do not have this limitation, as they are Unicode-based.
On NT-based Windows, this limitation does not apply either. On Windows, the PySide.QtCore.QCoreApplication.arguments() are not built from the contents of argv/argc, as the content does not support Unicode. Instead, the PySide.QtCore.QCoreApplication.arguments() are constructed from the return value of GetCommandLine(). As a result of this, the string given by PySide.QtCore.QCoreApplication.arguments() .at(0) might not be the program name on Windows, depending on how the application was started.
Return type: | PySide.QtCore.bool |
---|
Returns true if the application objects are being destroyed; otherwise returns false.
Return type: | PySide.QtCore.int |
---|
Enters the main event loop and waits until PySide.QtCore.QCoreApplication.exit() is called. Returns the value that was set to PySide.QtCore.QCoreApplication.exit() (which is 0 if PySide.QtCore.QCoreApplication.exit() is called via PySide.QtCore.QCoreApplication.quit() ).
It is necessary to call this function to start event handling. The main event loop receives events from the window system and dispatches these to the application widgets.
To make your application perform idle processing (i.e. executing a special function whenever there are no pending events), use a PySide.QtCore.QTimer with 0 timeout. More advanced idle processing schemes can be achieved using PySide.QtCore.QCoreApplication.processEvents() .
We recommend that you connect clean-up code to the PySide.QtCore.QCoreApplication.aboutToQuit() signal, instead of putting it in your application’s main() function because on some platforms the QCoreApplication.exec() call may not return. For example, on Windows when the user logs off, the system terminates the process after Qt closes all top-level windows. Hence, there is no guarantee that the application will have time to exit its event loop and execute code at the end of the main() function after the QCoreApplication.exec() call.
See also
PySide.QtCore.QCoreApplication.quit() PySide.QtCore.QCoreApplication.exit() PySide.QtCore.QCoreApplication.processEvents() QApplication.exec()
Parameters: | retcode – PySide.QtCore.int |
---|
Tells the application to exit with a return code.
After this function has been called, the application leaves the main event loop and returns from the call to exec() . The exec() function returns returnCode . If the event loop is not running, this function does nothing.
By convention, a returnCode of 0 means success, and any non-zero value indicates an error.
Note that unlike the C library function of the same name, this function does return to the caller – it is event processing that stops.
See also
Flushes the platform specific event queues.
If you are doing graphical changes inside a loop that does not return to the event loop on asynchronous window systems like X11 or double buffered window systems like Mac OS X, and you want to visualize these changes immediately (e.g. Splash Screens), call this function.
Return type: | PySide.QtCore.bool |
---|
This function returns true if there are pending events; otherwise returns false. Pending events can be either from the window system or posted events using PySide.QtCore.QCoreApplication.postEvent() .
Parameters: | messageFile – PySide.QtCore.QTranslator |
---|
Adds the translation file translationFile to the list of translation files to be used for translations.
Multiple translation files can be installed. Translations are searched for in the reverse order in which they were installed, so the most recently installed translation file is searched first and the first translation file installed is searched last. The search stops as soon as a translation containing a matching string is found.
Installing or removing a PySide.QtCore.QTranslator , or changing an installed PySide.QtCore.QTranslator generates a LanguageChange event for the PySide.QtCore.QCoreApplication instance. A PySide.QtGui.QApplication instance will propagate the event to all toplevel windows, where a reimplementation of changeEvent can re-translate the user interface by passing user-visible strings via the tr() function to the respective property setters. User-interface classes generated by Qt Designer provide a retranslateUi() function that can be called.
See also
PySide.QtCore.QCoreApplication.removeTranslator() PySide.QtCore.QCoreApplication.translate() QTranslator.load() Dynamic Translation
Return type: | PySide.QtCore.QCoreApplication |
---|
Returns a pointer to the application’s PySide.QtCore.QCoreApplication (or PySide.QtGui.QApplication ) instance.
If no instance has been allocated, null is returned.
Return type: | list of strings |
---|
Returns a list of paths that the application will search when dynamically loading libraries.
Qt provides default library paths, but they can also be set using a qt.conf file. Paths specified in this file will override default values.
This list will include the installation directory for plugins if it exists (the default installation directory for plugins is INSTALL/plugins , where INSTALL is the directory where Qt was installed). The directory of the application executable (NOT the working directory) is always added, as well as the colon separated entries of the QT_PLUGIN_PATH environment variable.
If you want to iterate over the list, you can use the foreach pseudo-keyword:
for path in app.libraryPaths():
do_something(path)
See also
PySide.QtCore.QCoreApplication.setLibraryPaths() PySide.QtCore.QCoreApplication.addLibraryPath() PySide.QtCore.QCoreApplication.removeLibraryPath() QLibrary How to Create Qt Plugins
Parameters: |
|
---|---|
Return type: | PySide.QtCore.bool |
Sends event to receiver : receiver ->event(event ). Returns the value that is returned from the receiver’s event handler. Note that this function is called for all events sent to any object in any thread.
For certain types of events (e.g. mouse and key events), the event will be propagated to the receiver’s parent and so on up to the top-level object if the receiver is not interested in the event (i.e., it returns false).
There are five different ways that events can be processed; reimplementing this virtual function is just one of them. All five approaches are listed below:
Parameters: |
|
---|---|
Return type: | PySide.QtCore.bool |
Return type: | unicode |
---|
This property holds the Internet domain of the organization that wrote this application.
The value is used by the PySide.QtCore.QSettings class when it is constructed using the empty constructor. This saves having to repeat this information each time a PySide.QtCore.QSettings object is created.
On Mac, PySide.QtCore.QSettings uses PySide.QtCore.QCoreApplication.organizationDomain() as the organization if it’s not an empty string; otherwise it uses PySide.QtCore.QCoreApplication.organizationName() . On all other platforms, PySide.QtCore.QSettings uses PySide.QtCore.QCoreApplication.organizationName() as the organization.
Return type: | unicode |
---|
This property holds the name of the organization that wrote this application.
The value is used by the PySide.QtCore.QSettings class when it is constructed using the empty constructor. This saves having to repeat this information each time a PySide.QtCore.QSettings object is created.
On Mac, PySide.QtCore.QSettings uses PySide.QtCore.QCoreApplication.organizationDomain() as the organization if it’s not an empty string; otherwise it uses PySide.QtCore.QCoreApplication.organizationName() . On all other platforms, PySide.QtCore.QSettings uses PySide.QtCore.QCoreApplication.organizationName() as the organization.
Parameters: |
|
---|
Adds the event event , with the object receiver as the receiver of the event, to an event queue and returns immediately.
The event must be allocated on the heap since the post event queue will take ownership of the event and delete it once it has been posted. It is not safe to access the event after it has been posted.
When control returns to the main event loop, all events that are stored in the queue will be sent using the PySide.QtCore.QCoreApplication.notify() function.
Events are processed in the order posted. For more control over the processing order, use the PySide.QtCore.QCoreApplication.postEvent() overload below, which takes a priority argument. This function posts all event with a Qt.NormalEventPriority .
Parameters: |
|
---|
This function overloads PySide.QtCore.QCoreApplication.postEvent() .
Adds the event event , with the object receiver as the receiver of the event, to an event queue and returns immediately.
The event must be allocated on the heap since the post event queue will take ownership of the event and delete it once it has been posted. It is not safe to access the event after it has been posted.
When control returns to the main event loop, all events that are stored in the queue will be sent using the PySide.QtCore.QCoreApplication.notify() function.
Events are sorted in descending priority order, i.e. events with a high priority are queued before events with a lower priority . The priority can be any integer value, i.e. between INT_MAX and INT_MIN, inclusive; see Qt.EventPriority for more details. Events with equal priority will be processed in the order posted.
Parameters: |
|
---|
Parameters: | flags – PySide.QtCore.QEventLoop.ProcessEventsFlags |
---|
Tells the application to exit with return code 0 (success). Equivalent to calling QCoreApplication::exit(0).
It’s common to connect the QApplication.lastWindowClosed() signal to PySide.QtCore.QCoreApplication.quit() , and you also often connect e.g. QAbstractButton.clicked() or signals in PySide.QtGui.QAction , PySide.QtGui.QMenu , or PySide.QtGui.QMenuBar to it.
Example:
quitButton = QPushButton("Quit")
quitButton.clicked.connect(app.quit)
See also
PySide.QtCore.QCoreApplication.exit() PySide.QtCore.QCoreApplication.aboutToQuit() QApplication.lastWindowClosed()
Parameters: | arg__1 – unicode |
---|
Removes path from the library path list. If path is empty or not in the path list, the list is not changed.
Parameters: | receiver – PySide.QtCore.QObject |
---|
Removes all events posted using PySide.QtCore.QCoreApplication.postEvent() for receiver .
The events are not dispatched, instead they are removed from the queue. You should never need to call this function. If you do call it, be aware that killing events may cause receiver to break one or more invariants.
Parameters: |
|
---|
This function overloads PySide.QtCore.QCoreApplication.removePostedEvents() .
Removes all events of the given eventType that were posted using PySide.QtCore.QCoreApplication.postEvent() for receiver .
The events are not dispatched, instead they are removed from the queue. You should never need to call this function. If you do call it, be aware that killing events may cause receiver to break one or more invariants.
If receiver is null, the events of eventType are removed for all objects. If eventType is 0, all the events are removed for receiver .
Parameters: | messageFile – PySide.QtCore.QTranslator |
---|
Removes the translation file translationFile from the list of translation files used by this application. (It does not delete the translation file from the file system.)
Parameters: |
|
---|---|
Return type: | PySide.QtCore.bool |
Sends event event directly to receiver receiver , using the PySide.QtCore.QCoreApplication.notify() function. Returns the value that was returned from the event handler.
The event is not deleted when the event has been sent. The normal approach is to create the event on the stack, for example:
event = QMouseEvent(QEvent.MouseButtonPress, pos, 0, 0, 0)
QApplication.sendEvent(mainWindow, event)
Parameters: |
|
---|
Immediately dispatches all events which have been previously queued with QCoreApplication.postEvent() and which are for the object receiver and have the event type event_type .
Events from the window system are not dispatched by this function, but by PySide.QtCore.QCoreApplication.processEvents() .
If receiver is null, the events of event_type are sent for all objects. If event_type is 0, all the events are sent for receiver .
Note
This method must be called from the same thread as its PySide.QtCore.QObject parameter, receiver .
This function overloads PySide.QtCore.QCoreApplication.sendPostedEvents() .
Dispatches all posted events, i.e. empties the event queue.
Parameters: |
|
---|---|
Return type: | PySide.QtCore.bool |
Parameters: | application – unicode |
---|
This property holds the name of this application.
The value is used by the PySide.QtCore.QSettings class when it is constructed using the empty constructor. This saves having to repeat this information each time a PySide.QtCore.QSettings object is created.
Parameters: | version – unicode |
---|
This property holds the version of this application.
Parameters: |
|
---|
Parameters: | arg__1 – list of strings |
---|
Sets the list of directories to search when loading libraries to paths . All existing paths will be deleted and the path list will consist of the paths given in paths .
In Symbian this function is only useful for setting paths for finding Qt extension plugin stubs, since the OS can only load libraries from the /sys/bin directory.
Parameters: | orgDomain – unicode |
---|
This property holds the Internet domain of the organization that wrote this application.
The value is used by the PySide.QtCore.QSettings class when it is constructed using the empty constructor. This saves having to repeat this information each time a PySide.QtCore.QSettings object is created.
On Mac, PySide.QtCore.QSettings uses PySide.QtCore.QCoreApplication.organizationDomain() as the organization if it’s not an empty string; otherwise it uses PySide.QtCore.QCoreApplication.organizationName() . On all other platforms, PySide.QtCore.QSettings uses PySide.QtCore.QCoreApplication.organizationName() as the organization.
Parameters: | orgName – unicode |
---|
This property holds the name of the organization that wrote this application.
The value is used by the PySide.QtCore.QSettings class when it is constructed using the empty constructor. This saves having to repeat this information each time a PySide.QtCore.QSettings object is created.
On Mac, PySide.QtCore.QSettings uses PySide.QtCore.QCoreApplication.organizationDomain() as the organization if it’s not an empty string; otherwise it uses PySide.QtCore.QCoreApplication.organizationName() . On all other platforms, PySide.QtCore.QSettings uses PySide.QtCore.QCoreApplication.organizationName() as the organization.
Return type: | PySide.QtCore.bool |
---|
Returns true if an application object has not been created yet; otherwise returns false.
Parameters: | attribute – PySide.QtCore.Qt.ApplicationAttribute |
---|---|
Return type: | PySide.QtCore.bool |
Parameters: |
|
---|---|
Return type: | unicode |
Returns the translation text for sourceText , by querying the installed translation files. The translation files are searched from the most recently installed file back to the first installed file.
QObject.tr() and QObject.trUtf8() provide this functionality more conveniently.
context is typically a class name (e.g., “MyDialog”) and sourceText is either English text or a short identifying text.
disambiguation is an identifying string, for when the same sourceText is used in different roles within the same context. By default, it is null.
See the PySide.QtCore.QTranslator and QObject.tr() documentation for more information about contexts, disambiguations and comments.
encoding indicates the 8-bit encoding of character strings.
n is used in conjunction with %n to support plural forms. See QObject.tr() for details.
If none of the translation files contain a translation for sourceText in context , this function returns a PySide.QtCore.QString equivalent of sourceText . The encoding of sourceText is specified by encoding ; it defaults to CodecForTr .
This function is not virtual. You can use alternative translation techniques by subclassing PySide.QtCore.QTranslator .
Warning
This method is reentrant only if all translators are installed before calling this method. Installing or removing translators while performing translations is not supported. Doing so will most likely result in crashes or other undesirable behavior.
Parameters: |
|
---|---|
Return type: | unicode |
This function overloads PySide.QtCore.QCoreApplication.translate() .
Parameters: | arg__1 – PySide.QtCore.int |
---|
Constructs a Qt kernel application. Kernel applications are applications without a graphical user interface. These type of applications are used at the console or as server processes.
The args argument is processed by the application, and made available in a more convenient form by the arguments() method.