All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.qt.core.QCoreApplication Maven / Gradle / Ivy

There is a newer version: 6.8.1
Show newest version
package io.qt.core;


/**
 * 

Event loop for Qt applications without UI

*

Java wrapper for Qt class QCoreApplication

*/ public class QCoreApplication extends io.qt.core.QObject { @io.qt.QtPropertyMember(enabled=false) private static java.util.Collection __rcTranslators; /** * This variable stores the meta-object for the class. */ public static final io.qt.core.QMetaObject staticMetaObject = io.qt.core.QMetaObject.forType(QCoreApplication.class); /** *

See QCoreApplication::aboutToQuit()

*/ public final PrivateSignal0 aboutToQuit = new PrivateSignal0(); /** *

See QCoreApplication::applicationNameChanged()

*/ @io.qt.QtPropertyNotify(name="applicationName") public final Signal0 applicationNameChanged = new Signal0(); /** *

See QCoreApplication::applicationVersionChanged()

*/ @io.qt.QtPropertyNotify(name="applicationVersion") public final Signal0 applicationVersionChanged = new Signal0(); /** *

See QCoreApplication::organizationDomainChanged()

*/ @io.qt.QtPropertyNotify(name="organizationDomain") public final Signal0 organizationDomainChanged = new Signal0(); /** *

See QCoreApplication::organizationNameChanged()

*/ @io.qt.QtPropertyNotify(name="organizationName") public final Signal0 organizationNameChanged = new Signal0(); protected QCoreApplication(java.lang.String[] argv){ super((QPrivateConstructor)null); if(!__qt_isInitializing){ throw new IllegalAccessError("Not allowed to instantiate QCoreApplication. Please use QCoreApplication.initialize() instead."); } initialize_native(this, argv); } private native static void initialize_native(QCoreApplication instance, java.lang.String[] argv); @io.qt.QtUninvokable private final QNativeInterface resolveInterface(java.lang.Class name){ return resolveInterface_native_const_char_ptr_int_constfct(QtJambi_LibraryUtilities.internal.nativeId(this), name); } @io.qt.QtUninvokable private native QNativeInterface resolveInterface_native_const_char_ptr_int_constfct(long __this__nativeId, java.lang.Class name); /** *

See QObject::event(QEvent*)

*/ @io.qt.QtUninvokable public boolean event(io.qt.core.QEvent arg__1){ return event_native_QEvent_ptr(QtJambi_LibraryUtilities.internal.nativeId(this), QtJambi_LibraryUtilities.internal.checkedNativeId(arg__1)); } @io.qt.QtUninvokable private native boolean event_native_QEvent_ptr(long __this__nativeId, long arg__1); /** *

See QCoreApplication::notify(QObject*,QEvent*)

*/ @io.qt.QtUninvokable public boolean notify(io.qt.core.QObject arg__1, io.qt.core.QEvent arg__2){ return notify_native_QObject_ptr_QEvent_ptr(QtJambi_LibraryUtilities.internal.nativeId(this), QtJambi_LibraryUtilities.internal.checkedNativeId(arg__1), QtJambi_LibraryUtilities.internal.checkedNativeId(arg__2)); } @io.qt.QtUninvokable private native boolean notify_native_QObject_ptr_QEvent_ptr(long __this__nativeId, long arg__1, long arg__2); /** *

See QCoreApplication::addLibraryPath(QString)

*/ public native static void addLibraryPath(java.lang.String arg__1); /** *

See QCoreApplication::applicationDirPath()

*/ public native static java.lang.String applicationDirPath(); /** *

See QCoreApplication::applicationFilePath()

*/ public native static java.lang.String applicationFilePath(); /** *

See QCoreApplication::applicationName()

*/ @io.qt.QtPropertyReader(name="applicationName") public native static java.lang.String applicationName(); /** *

See QCoreApplication::applicationPid()

*/ public native static long applicationPid(); /** *

See QCoreApplication::applicationVersion()

*/ @io.qt.QtPropertyReader(name="applicationVersion") public native static java.lang.String applicationVersion(); /** *

See QCoreApplication::arguments()

*/ public native static io.qt.core.QStringList arguments(); /** *

See QCoreApplication::closingDown()

*/ public native static boolean closingDown(); /** *

See QCoreApplication::eventDispatcher()

*/ public native static io.qt.core.QAbstractEventDispatcher eventDispatcher(); /** *

See QCoreApplication::exec()

*/ public native static int exec(); /** *

Overloaded function for {@link #exit(int)} * with retcode = 0.

*/ public static void exit() { exit((int)0); } /** *

See QCoreApplication::exit(int)

*/ public native static void exit(int retcode); /** *

See QCoreApplication::installTranslator(QTranslator*)

*/ public static boolean installTranslator(io.qt.core.QTranslator messageFile){ boolean __qt_return_value = installTranslator_native_QTranslator_ptr(QtJambi_LibraryUtilities.internal.checkedNativeId(messageFile)); if (messageFile != null) { if(__rcTranslators==null) __rcTranslators = QtJambi_LibraryUtilities.internal.newRCList(); __rcTranslators.add(messageFile); } return __qt_return_value; } private native static boolean installTranslator_native_QTranslator_ptr(long messageFile); /** *

See QCoreApplication::instance()

*/ public native static io.qt.core.QCoreApplication instance(); /** *

See QCoreApplication::isQuitLockEnabled()

*/ @io.qt.QtPropertyReader(name="quitLockEnabled") public native static boolean isQuitLockEnabled(); /** *

See QCoreApplication::isSetuidAllowed()

*/ public native static boolean isSetuidAllowed(); /** *

See QCoreApplication::libraryPaths()

*/ public native static io.qt.core.QStringList libraryPaths(); /** *

See QCoreApplication::organizationDomain()

*/ @io.qt.QtPropertyReader(name="organizationDomain") public native static java.lang.String organizationDomain(); /** *

See QCoreApplication::organizationName()

*/ @io.qt.QtPropertyReader(name="organizationName") public native static java.lang.String organizationName(); /** *

Overloaded function for {@link #postEvent(io.qt.core.QObject, io.qt.core.QEvent, int)} * with priority = 0.

*/ public static void postEvent(io.qt.core.QObject receiver, io.qt.core.QEvent event) { postEvent(receiver, event, (int)0); } /** *

See QCoreApplication::postEvent(QObject*,QEvent*,int)

*/ public static void postEvent(io.qt.core.QObject receiver, io.qt.core.QEvent event, int priority){ postEvent_native_QObject_ptr_QEvent_ptr_int(QtJambi_LibraryUtilities.internal.checkedNativeId(receiver), QtJambi_LibraryUtilities.internal.checkedNativeId(event), priority); } private native static void postEvent_native_QObject_ptr_QEvent_ptr_int(long receiver, long event, int priority); /** *

Overloaded function for {@link #processEvents(io.qt.core.QEventLoop.ProcessEventsFlags)}.

*/ public static void processEvents(io.qt.core.QEventLoop.ProcessEventsFlag ... flags){ processEvents(new io.qt.core.QEventLoop.ProcessEventsFlags(flags)); } /** *

Overloaded function for {@link #processEvents(io.qt.core.QEventLoop.ProcessEventsFlags)} * with flags = new io.qt.core.QEventLoop.ProcessEventsFlags(0).

*/ public static void processEvents() { processEvents(new io.qt.core.QEventLoop.ProcessEventsFlags(0)); } /** *

See QCoreApplication::processEvents(QEventLoop::ProcessEventsFlags)

*/ public static void processEvents(io.qt.core.QEventLoop.ProcessEventsFlags flags){ processEvents_native_QFlags_QEventLoop_ProcessEventsFlag_(flags.value()); } private native static void processEvents_native_QFlags_QEventLoop_ProcessEventsFlag_(int flags); /** *

See QCoreApplication::processEvents(QEventLoop::ProcessEventsFlags,int)

*/ public static void processEvents(io.qt.core.QEventLoop.ProcessEventsFlags flags, int maxtime){ processEvents_native_QFlags_QEventLoop_ProcessEventsFlag__int(flags.value(), maxtime); } private native static void processEvents_native_QFlags_QEventLoop_ProcessEventsFlag__int(int flags, int maxtime); /** *

See QCoreApplication::quit()

*/ public native static void quit(); /** *

See QCoreApplication::removeLibraryPath(QString)

*/ public native static void removeLibraryPath(java.lang.String arg__1); /** *

Overloaded function for {@link #removePostedEvents(io.qt.core.QObject, int)} * with eventType = 0.

*/ public static void removePostedEvents(io.qt.core.QObject receiver) { removePostedEvents(receiver, (int)0); } /** *

See QCoreApplication::removePostedEvents(QObject*,int)

*/ public static void removePostedEvents(io.qt.core.QObject receiver, int eventType){ removePostedEvents_native_QObject_ptr_int(QtJambi_LibraryUtilities.internal.checkedNativeId(receiver), eventType); } private native static void removePostedEvents_native_QObject_ptr_int(long receiver, int eventType); /** *

See QCoreApplication::removeTranslator(QTranslator*)

*/ public static boolean removeTranslator(io.qt.core.QTranslator messageFile){ boolean __qt_return_value = removeTranslator_native_QTranslator_ptr(QtJambi_LibraryUtilities.internal.checkedNativeId(messageFile)); if (messageFile != null) { while (__rcTranslators != null && __rcTranslators.remove(messageFile)) ; } return __qt_return_value; } private native static boolean removeTranslator_native_QTranslator_ptr(long messageFile); /** *

See QCoreApplication::sendEvent(QObject*,QEvent*)

*/ public static boolean sendEvent(io.qt.core.QObject receiver, io.qt.core.QEvent event){ return sendEvent_native_QObject_ptr_QEvent_ptr(QtJambi_LibraryUtilities.internal.checkedNativeId(receiver), QtJambi_LibraryUtilities.internal.checkedNativeId(event)); } private native static boolean sendEvent_native_QObject_ptr_QEvent_ptr(long receiver, long event); /** *

Overloaded function for {@link #sendPostedEvents(io.qt.core.QObject, int)} * with event_type = 0.

*/ public static void sendPostedEvents(io.qt.core.QObject receiver) { sendPostedEvents(receiver, (int)0); } /** *

Overloaded function for {@link #sendPostedEvents(io.qt.core.QObject, int)}

*

with:

    *
  • receiver = null
  • *
  • event_type = 0
  • *
*/ public static void sendPostedEvents() { sendPostedEvents((io.qt.core.QObject)null, (int)0); } /** *

See QCoreApplication::sendPostedEvents(QObject*,int)

*/ public static void sendPostedEvents(io.qt.core.QObject receiver, int event_type){ sendPostedEvents_native_QObject_ptr_int(QtJambi_LibraryUtilities.internal.checkedNativeId(receiver), event_type); } private native static void sendPostedEvents_native_QObject_ptr_int(long receiver, int event_type); /** *

See QCoreApplication::setApplicationName(QString)

*/ @io.qt.QtPropertyWriter(name="applicationName") public native static void setApplicationName(java.lang.String application); /** *

See QCoreApplication::setApplicationVersion(QString)

*/ @io.qt.QtPropertyWriter(name="applicationVersion") public native static void setApplicationVersion(java.lang.String version); /** *

Overloaded function for {@link #setAttribute(io.qt.core.Qt.ApplicationAttribute, boolean)} * with on = true.

*/ public static void setAttribute(io.qt.core.Qt.ApplicationAttribute attribute) { setAttribute(attribute, (boolean)true); } /** *

See QCoreApplication::setAttribute(Qt::ApplicationAttribute,bool)

*/ public static void setAttribute(io.qt.core.Qt.ApplicationAttribute attribute, boolean on){ setAttribute_native_Qt_ApplicationAttribute_bool(attribute.value(), on); } private native static void setAttribute_native_Qt_ApplicationAttribute_bool(int attribute, boolean on); /** *

See QCoreApplication::setEventDispatcher(QAbstractEventDispatcher*)

*/ public static void setEventDispatcher(io.qt.core.QAbstractEventDispatcher eventDispatcher){ setEventDispatcher_native_QAbstractEventDispatcher_ptr(QtJambi_LibraryUtilities.internal.checkedNativeId(eventDispatcher)); QtJambi_LibraryUtilities.internal.setReferenceCount(instance().thread(), QThread.class, "__rcEventDispatcher", false, false, eventDispatcher); } private native static void setEventDispatcher_native_QAbstractEventDispatcher_ptr(long eventDispatcher); /** *

See QCoreApplication::setLibraryPaths(QStringList)

*/ public native static void setLibraryPaths(java.util.Collection arg__1); /** *

See QCoreApplication::setOrganizationDomain(QString)

*/ @io.qt.QtPropertyWriter(name="organizationDomain") public native static void setOrganizationDomain(java.lang.String orgDomain); /** *

See QCoreApplication::setOrganizationName(QString)

*/ @io.qt.QtPropertyWriter(name="organizationName") public native static void setOrganizationName(java.lang.String orgName); /** *

See QCoreApplication::setQuitLockEnabled(bool)

*/ @io.qt.QtPropertyWriter(name="quitLockEnabled") public native static void setQuitLockEnabled(boolean enabled); /** *

See QCoreApplication::setSetuidAllowed(bool)

*/ public native static void setSetuidAllowed(boolean allow); /** *

See QCoreApplication::startingUp()

*/ public native static boolean startingUp(); /** *

See QCoreApplication::testAttribute(Qt::ApplicationAttribute)

*/ public static boolean testAttribute(io.qt.core.Qt.ApplicationAttribute attribute){ return testAttribute_native_Qt_ApplicationAttribute(attribute.value()); } private native static boolean testAttribute_native_Qt_ApplicationAttribute(int attribute); /** *

Overloaded function for {@link #translate(java.lang.String, java.lang.String, java.lang.String, int)} * with n = -1.

*/ public static java.lang.String translate(java.lang.String context, java.lang.String key, java.lang.String disambiguation) { return translate(context, key, disambiguation, (int)-1); } /** *

Overloaded function for {@link #translate(java.lang.String, java.lang.String, java.lang.String, int)}

*

with:

    *
  • disambiguation = null
  • *
  • n = -1
  • *
*/ public static java.lang.String translate(java.lang.String context, java.lang.String key) { return translate(context, key, (java.lang.String)null, (int)-1); } /** *

See QCoreApplication::translate(const char*,const char*,const char*,int)

*/ public native static java.lang.String translate(java.lang.String context, java.lang.String key, java.lang.String disambiguation, int n); /** * Constructor for internal use only. * @param p expected to be null. */ @io.qt.NativeAccess protected QCoreApplication(QPrivateConstructor p) { super(p); } private static boolean __qt_isInitializing = false; @io.qt.QtUninvokable private static native void preinit(); /** *

Overloaded function for {@link #sendPostedEvents(io.qt.core.QObject, int)}

*/ public static void sendPostedEvents(io.qt.core.QObject receiver, QEvent.Type event_type){ sendPostedEvents(receiver, event_type.value()); } /** * Initializes the QCoreApplication with the given arguments. * @param args * @return QCoreApplication instance */ @io.qt.QtUninvokable public static QCoreApplication initialize(String args[]) { return initialize(null, args, QCoreApplication::new); } /** * Initializes the QCoreApplication with the given arguments and applicationName. * @param applicationName * @param args * @return QCoreApplication instance */ @io.qt.QtUninvokable public static QCoreApplication initialize(String applicationName, String args[]) { return initialize(applicationName, args, QCoreApplication::new); } /** * Initializes a custom QCoreApplication subclass with the given arguments. * @param QCoreApplication subclass * @param args * @param constructor * @return T instance */ @io.qt.QtUninvokable public static T initialize(String args[], java.util.function.Function constructor) { return initialize(null, args, constructor); } /** * Initializes a custom QCoreApplication subclass with the given arguments and applicationName. * @param QCoreApplication subclass * @param applicationName * @param args * @param constructor * @return T instance */ @io.qt.QtUninvokable public static T initialize(String applicationName, String args[], java.util.function.Function constructor) { if (instance() != null) throw new RuntimeException("QCoreApplication can only be initialized once"); preinit(); String[] _args = new String[args.length+1]; if(applicationName!=null && !applicationName.isEmpty()){ _args[0] = applicationName; setApplicationName(applicationName); }else{ _args[0] = applicationName(); } System.arraycopy(args, 0, _args, 1, args.length); args = _args; __qt_isInitializing = true; try { T application = java.util.Objects.requireNonNull(constructor.apply(args), "Constructor function does not instantiate QCoreApplication."); QtJambi_LibraryUtilities.internal.setCppOwnership(application); removeLibraryPath(QDir.fromNativeSeparators(System.getProperty("sun.boot.library.path"))); QDir userDir = new QDir(System.getProperty("user.dir")); if(userDir.cd("plugins")){ addLibraryPath(userDir.canonicalPath()); } return application; } catch (Error e) { throw e; } catch (RuntimeException e) { throw e; } catch (Throwable e) { throw new RuntimeException("Cannot initialize QCoreApplication", e); }finally{ __qt_isInitializing = false; } } /** * Destroys the QCoreApplication instance and purges Qt. */ @io.qt.QtUninvokable public static void shutdown() { QCoreApplication app = instance(); if(app != null) { QThread currentThread = QThread.currentThread(); if(currentThread!=app.thread()) throw new io.qt.QThreadAffinityException("Must not call QCoreApplication.shutdown() from outside main thread.", null, app.thread(), currentThread); if(app.thread().loopLevel()>0) throw new IllegalStateException("Must not call QCoreApplication.shutdown() in event loop."); System.gc(); System.runFinalization(); QCoreApplication.sendPostedEvents(null, QEvent.Type.DeferredDispose.value()); // allow deleteLater() to work some magic processEvents(); // process quit QCoreApplication.sendPostedEvents(null, QEvent.Type.DeferredDispose.value()); // allow deleteLater() to work some magic if(app instanceof io.qt.gui.QGuiApplication) { boolean deleted = false; if(app instanceof io.qt.widgets.QApplication) { for(io.qt.widgets.QWidget widget : new java.util.ArrayList<>(io.qt.widgets.QApplication.topLevelWidgets())) { if(widget!=null && !widget.isDisposed() && QtJambi_LibraryUtilities.internal.isJavaOwnership(widget)) { widget.dispose(); deleted = true; } } // second chance for(io.qt.widgets.QWidget widget : new java.util.ArrayList<>(io.qt.widgets.QApplication.topLevelWidgets())) { if(widget!=null && !widget.isDisposed()) { if(!QtJambi_LibraryUtilities.internal.isJavaOwnership(widget)) QLogging.qWarning("QCoreApplication.shutdown() called before closing all widgets. Deleting widget %1$s [\"%2$s\"] (%3$s).", widget.objectName(), widget.windowTitle(), widget.metaObject().className()); widget.dispose(); deleted = true; } } } for(io.qt.gui.QWindow window : new java.util.ArrayList<>(io.qt.gui.QGuiApplication.topLevelWindows())) { if(window!=null && !window.isDisposed() && QtJambi_LibraryUtilities.internal.isJavaOwnership(window)) { if(currentThread==window.thread()) window.dispose(); else window.disposeLater(); deleted = true; } } // second chance for(io.qt.gui.QWindow window : new java.util.ArrayList<>(io.qt.gui.QGuiApplication.topLevelWindows())) { if(window!=null && !window.isDisposed()) { if(!QtJambi_LibraryUtilities.internal.isJavaOwnership(window)) QLogging.qWarning("QCoreApplication.shutdown() called before closing all windows. Deleting window %1$s [\"%2$s\"] (%3$s).", window.objectName(), window.title(), window.metaObject().className()); if(currentThread==window.thread()) window.dispose(); else window.disposeLater(); deleted = true; } } if(deleted){ System.gc(); System.runFinalization(); QCoreApplication.sendPostedEvents(null, QEvent.Type.DeferredDispose.value()); // allow deleteLater() to work some magic processEvents(); // process quit QCoreApplication.sendPostedEvents(null, QEvent.Type.DeferredDispose.value()); // allow deleteLater() to work some magic } } app.dispose(); app = null; // discard hard-reference System.gc(); System.runFinalization(); QCoreApplication.sendPostedEvents(null, QEvent.Type.DeferredDispose.value()); // allow deleteLater() to work some magic processEvents(); // process quit QCoreApplication.sendPostedEvents(null, QEvent.Type.DeferredDispose.value()); // allow deleteLater() to work some magic } if (instance() != null) QLogging.qWarning("Failed to delete QCoreApplication instance."); System.gc(); System.runFinalization(); QCoreApplication.sendPostedEvents(null, QEvent.Type.DeferredDispose.value()); } /** * Adds a pre-routine to be executed before initializing QCoreApplication. * @see initialize(String[]) */ @io.qt.QtUninvokable public static void addPreRoutine(Runnable startUpFunction) { preRoutines.add(startUpFunction); } /** * Adds a post-routine to be executed when deleting QCoreApplication. * @see shutdown() */ @io.qt.QtUninvokable public static void addPostRoutine(Runnable cleanUpFunction) { postRoutines.add(cleanUpFunction); } /** * Removes a previously added post-routine. * @see addPostRoutine(Runnable) * @see shutdown() */ @io.qt.QtUninvokable public static void removePostRoutine(Runnable cleanUpFunction){ postRoutines.remove(cleanUpFunction); } private static final java.util.List preRoutines = java.util.Collections.synchronizedList(new java.util.ArrayList<>()); private static final java.util.List postRoutines = java.util.Collections.synchronizedList(new java.util.ArrayList<>()); @io.qt.NativeAccess @io.qt.QtUninvokable private static void execPreRoutines() { for(Runnable preRoutine : new java.util.ArrayList<>(preRoutines)) { try { preRoutine.run(); }catch(Throwable t) { java.util.logging.Logger.getLogger("io.qt.core").throwing("Runnable", "run", t); } } preRoutines.clear(); } @io.qt.NativeAccess @io.qt.QtUninvokable private static void execPostRoutines() { for(Runnable postRoutine : new java.util.ArrayList<>(postRoutines)) { try { postRoutine.run(); }catch(Throwable t) { java.util.logging.Logger.getLogger("io.qt.core").throwing("Runnable", "run", t); } } postRoutines.clear(); } @io.qt.QtUninvokable public final QNativeInterface nativeInterface(Class nativeInterfaceClass) { return resolveInterface(nativeInterfaceClass); } }