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
2 answers

What SIGNAL is emitted in Qt when pressing the "X" on the top right corner to terminate the Window?

Which SIGNAL is emitted, when pressing the "X" in the top right corner of a Qt Window application? I have a second QDialog widget beside my MainWindow in my Qt application. And I would like to intercept the press on the "X" in my second QDialog,…
Ralf Wickum
  • 2,850
  • 9
  • 55
  • 103
1
vote
2 answers

QApplication::processEvents not working in Windows

I am working on a project that presents live data acquired in real-time using the QCustomPlot plug-in for Qt. The display has a black background color, and the multiple channels of data are colored differently. When taking a screenshot, we would…
casparjespersen
  • 3,460
  • 5
  • 38
  • 63
1
vote
1 answer

Prevent QApplication app from closing if a service is running

I have a QML app in which I have subclassed QApplication to create my main screen with QML. The issue i have is on clicking Close button the application closes as intended, but I want to handle a situation where if some services are running I want…
prakashpun
  • 259
  • 4
  • 19
1
vote
2 answers

Qt - Dialog in a DLL

In my company, we are developing with Embarcadero-C++-IDE (which is very uncomfortable). To start moving away, we port individual dialogs in a dll to Qt. My qt-dll-code Looks like this for example extern "C" ROBOTECHPOLYLINEDIALOGSHARED_EXPORT void…
mathgenius
  • 165
  • 1
  • 13
1
vote
1 answer

How to add an action item in a QT/C++ application

I have created an application in Qt/C++, by default, I have in my main : int main(int argc, char *argv[]) { QApplication app(argc, argv); MainUI MyWindow(*MyData); MyWindow.show(); return app.exec(); } MainUi is a class which is…
Seb
  • 2,929
  • 4
  • 30
  • 73
1
vote
1 answer

How to use threads to instantiating multiple QApplication

I found a solution to prevent app.exec() from blocking the main thread here. I tried to implement this but I got the following errors: WARNING: QApplication was not created in the main() thread. QWidget: Cannot create a QWidget without…
jlcv
  • 1,688
  • 5
  • 21
  • 50
1
vote
1 answer

Not able to connect aboutToQuit signal from QApplication

I have a Qt Application which i want to show in the System Tray. My desired behavior is that if the user clicks the close button of the Application than that application hides in the system tray but does not exit. My code in main.cpp is : if…
bourne
  • 1,083
  • 4
  • 14
  • 27
1
vote
1 answer

How to confirm the successful exit of the QApplication

I am working on a project which uses Qt for GUI development. Qt event loop is started in the main thread. But I have requirement to do some cleanup activities after the QApplication exits. So I have used qApp->quit() for exiting the application and…
SRaju
  • 31
  • 3
1
vote
1 answer

Get list of widgets for QGuiApplication

I need to get list of UI elements on the application main window (all windows, doesn't matter). The problem is that there is no topLevelWidgets() function in QGuiApplication, it is in QApplication. Of course I could use QApplication instead of…
incognito
  • 457
  • 5
  • 19
1
vote
1 answer

Qt 4 - QProcess problems

I'm trying to compile a Qt 4 Application which contains the call of QProcess. It's no problem to compile it as Release-Version, but I always get a SegmentionFault-Error when i execute the Debug-Version. My Qt version is 4.8.2 and i tried it on…
1
vote
3 answers

How to finish Qt programm from any place?

My example: main.cpp: QApplication a(argc, argv); MainWindow w; w.start(); return a.exec(); w.start(): if (cf.exec()){ this->show(); } else { qDebug()<<"Need exit"; //here should be exit } At…
Maksim Nesterenko
  • 5,661
  • 11
  • 57
  • 91
1
vote
2 answers

Hiding and relaunching the same instance of QApplication in Qt

I have a QApplication in which I have a custom QDialog. The dialog offers the users a set of options and then launches a process via QProcess. While the process launched still runs, the app if closed has to still run. To achieve this, I…
Bharath
  • 75
  • 8
1
vote
2 answers

MSVC2012 Qt supposed to include a directory?

I built a custom Qt5 for msvc2012 using BlueGo. I was reading the examples and they show this: #include int main(int argc, char *argv[]) { QApplication app(argc, argv); QWidget window; window.resize(320, 240); …
kvanbere
  • 3,289
  • 3
  • 27
  • 52
0
votes
1 answer

QT5's QApplication::setOverrideCursor(Qt::WaitCursor); is blocking the previous operations

In my loadDatabase function, I have clearly set the status to display the message "loading coverage database..." before setOverrideCursor(Qt::WaitCursor), but the status bar is only displaying the message after restoreOverrideCursor() is called. I…
piggogo
  • 11
  • 2
0
votes
2 answers

AttributeError: module 'pyqtgraph.Qt.QtGui' has no attribute 'QApplication'."

Details about my system; Ubunttu 22.04.2 LTS x86_64 pyqtgraph v0.13.1 pyhton v3.10 The code I'm trying to run on line 56; from pyqtgraph.Qt import QtGui, QtCore import pyqtgraph as pg app = QtGui.QApplication([]) The Error I get; AttributeError:…
Gordon Freeman
  • 133
  • 1
  • 1
  • 5