Questions tagged [qapplication]

The QApplication class is part of the Qt C++ classes manages the GUI application's control flow and main settings.

The QApplication class manages the application's control flow and main settings. QApplication specializes QGuiApplication with some functionality needed for QWidget-based applications. It handles widget specific initialization, finalization.

For any GUI application using Qt, there is precisely one QApplication object, no matter whether the application has 0, 1, 2 or more windows at any given time.

Some GUI applications provide a special batch mode ie. provide command line arguments for executing tasks without manual intervention. In such non-GUI mode, it is often sufficient to instantiate a plain QCoreApplication to avoid unnecessarily initializing resources needed for a graphical user interface.

The QApplication object is accessible through the instance() function that returns a pointer equivalent to the global qApp pointer.

QApplication's main areas of responsibility are:

  • It initializes the application with the user's desktop settings such as palette(), font() and doubleClickInterval(). It keeps track of these properties in case the user changes the desktop globally, for example through some kind of control panel.
  • It performs event handling, meaning that it receives events from the underlying window system and dispatches them to the relevant widgets. By using sendEvent() and postEvent() you can send your own events to widgets.
  • It parses common command line arguments and sets its internal state accordingly. See the constructor documentation below for more details.
  • It defines the application's look and feel, which is encapsulated in a QStyle object. This can be changed at runtime with setStyle().
  • It specifies how the application is to allocate colors. See setColorSpec() for details.
  • It provides localization of strings that are visible to the user via translate().
  • It provides some magical objects like the desktop() and the clipboard().
  • It knows about the application's windows. You can ask which widget is at a certain position using widgetAt(), get a list of topLevelWidgets() and closeAllWindows(), etc.
  • It manages the application's mouse cursor handling, see setOverrideCursor().
160 questions
1
vote
1 answer

Terminate application if subprocess ends

I have an application that is doing some data processing in its main thread. So far it was a pure console application. Now I had to add a QT App for visualization purpose and did this as a separate thread. If the QT Window is closed, the main thread…
po.pe
  • 1,047
  • 1
  • 12
  • 27
1
vote
1 answer

PySide2 crash when creating QApplication subclass within main()

I have a PySide2 (5.15.2.1) app on macOS 10.14.6 that works fine under Python 3.6 and 3.7 but crashes under Python 3.8. The minimal crashing example (seg fault 11) is: from PySide2 import QtCore, QtWidgets from PySide2.QtCore import Qt class…
jamesbcd
  • 11
  • 2
1
vote
0 answers

Qt Custom QObject Static Library with CMake Problem

I am working on a cmake qt project. While I was trying to compile a custom library, which is a QObject, and a custom executable, which is a QApplication, a linker error was occured. [build] Undefined symbols for architecture x86_64: [build] …
1
vote
1 answer

Pyqt5 - how to go back to hided Main Window from Secondary Window?

If I click Back from the second window, the program will just exit. How do I go back to mainwindow in this case? I assume I will need some more code in that clickMethodBack function. import os import PyQt5 from PyQt5 import QtCore, QtWidgets from…
wwj123
  • 365
  • 2
  • 12
1
vote
1 answer

Maya wait for Qt window to close

Normally in Qt applications you would use this at the start and end of your code: app = QtWidgets.QApplication(sys.argv) ... app.exec_() But in Maya, you don't use this because Qt runs on the Maya application it self. I'm sure this works the same…
Frank
  • 2,109
  • 7
  • 25
  • 48
1
vote
1 answer

PySide2 + QML : QApplication: invalid style override passed, ignoring it

I'm building a simple app using QML + PySide / Python as backend. I'm trying to use "Universal" qml style. I'm subclassing QApplication and adding -style Universal argument : class MyApp(QApplication): def __init__(self, args): qt_args =…
Paul Parneix
  • 129
  • 1
  • 9
1
vote
1 answer

Apply changed environment variables to QApplication at runtime

I'm trying to run qputenv("QT_DEBUG_PLUGINS", "1"); at runtime after an evaluation made by a QT application's MainWindow. I'm assuming that for it the new env vars to actually apply I must close the initialized QApplication and restart it but I…
Klypto
  • 434
  • 1
  • 3
  • 14
1
vote
1 answer

Run an application and quit it after rendering on PyQt5

I would like to render SVG files with PyQt5. The simplest way to do that is to use QSvgGenerator applied on a QPainter object. However, for some reason I have to render text in the output SVG file. To do that, having a QApplication running is…
Benjamin Barrois
  • 2,566
  • 13
  • 30
1
vote
1 answer

How to execute PyQt5 application on a resful call

Context: I have a Flask application serving a resource POST /start. The logic to be executed involves a PyQt5 QWebEnginePage loading a URL and returning certain data about it. Problem: When the QApplication is executed (calling app.exec_()) I get…
eriel marimon
  • 1,230
  • 1
  • 19
  • 29
1
vote
1 answer

QQuickWindow in shared lib auto close when show in QApplication

I develop a generic interface library with qt. I have trouble with pressed effect on QPushbutton when I click with a touch screen (this effect appears one time on 10 click). So I create a basic qml application with one button and pressed effect…
1
vote
1 answer

Qt project doesn't compile, undefined reference to

Main.cpp #include int main (int argc, char* argv[]) { QApplication app(argc, argv); return app.exec(); } test.pro SOURCES += \ main.cpp greaterThan(QT_MAJOR_VERSION,4) : QT +=widgets outputs : I can't compile my…
Clément
  • 75
  • 7
1
vote
1 answer

Can I use QApplication AND QCoreApplication?

I have a console application using QCoreApplication in Qt5. This application has different functions like "printABC" or "printSUV". The output will appear in the terminal. Now I want to make a Gui, where I can push the buttons "printABC" or…
pjs
  • 39
  • 1
  • 4
1
vote
2 answers

PyQt5 Resize app for different displays

I am using PyQt5 and Python 3.6.4 to design a ui for a program. It was made on a 720p monitor however now using the same code on a 4k monitor, everything is tiny apart from the text. How would I go about resizing the whole app to look the same on…
Kermit
  • 329
  • 6
  • 19
1
vote
0 answers

Parent Qt to non-qt window with PyQt

I am trying to parent a QMainWindow to a non-qt application (the application may change). Any ideas on how to do this? The qt window opens fine and i can interact with the python API in the applications however the qt window goes behind the…
Mafster
  • 107
  • 1
  • 3
  • 12
1
vote
1 answer

Qt Segmentation fault at exec()

I have a very strange problem while trying to run a QProcess in a class HmiApplication, which is derived from QApplication. The application throws a SIGSEGV in line 6 of main.cpp. This occurs only if line 11 of hmiapplication.cpp is commented out…
chrizbee
  • 145
  • 1
  • 13