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

Please instantiate the QApplication object first

I have a static class and want it to have static QSettings. But with my initialization I get a warning: QSettings* MySQLConnection::settings = new QSettings(QApplication::applicationDirPath() + "/config.ini",…
honiahaka10
  • 772
  • 4
  • 9
  • 29
4
votes
3 answers

What is difference between QTimer timeout slot calling a slot through direct connection or queued connection?

I'm asking in a case where there is a lot of qt events queued in event engine. Does QTimer emit timeout() signal through event and will with queuedConnection to a slot create another event?
Anže
  • 181
  • 8
4
votes
2 answers

How can I simulate mouse clicks by posting events to the Qt event system?

I would like to do a rudimentary automation test of my Qt application. It records mouse events and writes them to a file (f.e. mousepress(300, 400)). When starting the automation, it reads the coordinates from the file, sends the appropriate mouse…
user2246120
  • 1,453
  • 2
  • 17
  • 38
4
votes
1 answer

How to set an application icon in Qt

I have some trouble trying to set an icon for my QT application. The icon is named "room.ico" and is on the same directory as the source file. Here is the code : #include #include int main( int argc, char *argv[ ] ) { …
The Beast
  • 1,629
  • 2
  • 29
  • 42
4
votes
1 answer

Is it ok to use Qt metatype system before QApplication is created?

I use following code whenever I need to register a type in Qt metaobject system: *.h file class MyClass { //..... class MyType {.....}; static const int metaType_MyType; class MetaClerk { public: MetaClerk(void); …
ScumCoder
  • 690
  • 1
  • 8
  • 20
4
votes
1 answer

Why does QApplication give memory leaks?

I have a simple code: #include int main(int argc, char *argv[]) { QApplication a(argc, argv); return 0; } I compile it in Qt Creator using pro file: QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT +=…
user2717575
  • 369
  • 7
  • 16
3
votes
2 answers

QT5 error: Unknown type name 'QCoreApplication'. First program in Qt5

I have just installed QTCreator in Linux Ubuntu 20.04 LTS, I clicked on File->New Project->Application->QTConsole Application. A first.pro file and main.cpp file was made. The first.pro contains: QT -= gui declarative QT += widgets CONFIG += c++11…
3
votes
1 answer

Make a transparent hole in a QT application

I've got a problem where I've got 2 Qt applications on top of eachother. The top Qt application needs a transparant hole in it to show the Qt application behind it. Is there any way to do this? or is there an example somewhere in the Qt library…
Red-ER
  • 173
  • 2
  • 11
3
votes
0 answers

QApplication and SIGTERM

Why doesn't QApplication handle SIGTERM (and any other) signal and exit gracefully? Are there any good reasons not to do it?
groaner
  • 540
  • 4
  • 12
3
votes
1 answer

PyQtGraph: Issue looping through plotting slices of data

I have a python class that generates a numpy array of size 10000 and performs some calculation on it. The class has two plot methods and both use pyqtgraph Plotting the entire data Plotting segments of data one at a time (200 samples) I was…
afp_2008
  • 1,940
  • 1
  • 19
  • 46
3
votes
1 answer

How to listen to QGuiApplication::applicationStateChanged signals directly in a QML file

I am running my Qt application on Qt 5.9.3 on Android and iOS. I want to listen to QGuiApplication::applicationStateChanged directly on a QML file How can I listen to application state changes on QML using connection without having to write any code…
TheWaterProgrammer
  • 7,055
  • 12
  • 70
  • 159
3
votes
1 answer

How can I stop a QApplication from showing up in the dock?

I'm making a console application on OS X that interacts with specific parts of the Desktop Environment (mainly the mouse using QCursor), so I cannot use a QCoreApplication (despite how much I want to). The application works fine, it is just that it…
Flare Cat
  • 591
  • 2
  • 12
  • 24
3
votes
1 answer

MainWindow closes after initialization

I wanted to start a new project using PyQt5 and QtDesigner. To start, I just copied the code I had from previous projects in PyQt4 and tweaked it to the changes in PyQt5. So, the code to start the Main Window and a Timer which updates the…
Domino
  • 61
  • 1
  • 5
3
votes
1 answer

creating QApplication in a different thread

I'm trying to create QApplication in a different thread, but found 2 main problems: 1- I can't interact with GUI 2- some warnings: WARNING: QApplication was not created in the main() thread. QObject::startTimer: timers cannot be started from…
Mohamed Sakr
  • 409
  • 4
  • 16
3
votes
1 answer

PyQt: How to stick a widget to the bottom edge of dialog

Running this code creates a simple dialog with a label, lineedit and two buttons. All the widgets beautifully respond to the dialog horizontal resizing. But the buttons at the bottom of the dialog do not stick to the lower edge of dialog window…
alphanumeric
  • 17,967
  • 64
  • 244
  • 392
1
2
3
10 11