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
0
votes
0 answers

running 4 functions periodically in the background without freezing the GUI

I made a pyqt5 script which uses python3.6 my scripts takes input from serial device and updates the GUI and the remote database and also take remote input from web browser and make necessary changes to the serial device and update the GUI…
jyoti
  • 21
  • 1
  • 9
0
votes
1 answer

Qt - run function on other thread

In my simple QApplication I have this scenario: Class1 called from main thread. Class2 called from other thread that contains a reference of Class1. Is possible call Class1 function from Class2 using main thread? I have tried with moveToThread…
daniele86
  • 147
  • 3
  • 14
0
votes
0 answers

Usage of QVBoxLayout or QListWidgetItem causes "Access violation" Exception in QApplication::exec() inside DLL

Im trying to implement a DLL which displays a non modal QT window, when you call the exported "OpenUI()" function. The "Access violation reading location ..." occurs when the "OpenUI()" function is called a second time, after closing it the first…
Luk
  • 1
  • 2
0
votes
3 answers

Python - PyQt5 [PyQt5.QtWidgets import QApplication 'No Module']

I have been attempting to learn PyQt5 in order to create GUI. Pip installed the PyQt5 & the PyQt5.tools yet when I attempt to use it using Visual Studio Code (while having the Python Extension of VS Code installed) I receive an error. VS Code…
Ishay Cohen
  • 7
  • 1
  • 1
  • 5
0
votes
0 answers

"Show all windows" macos dock icon giving error

I have Qt application running on macos. There to be consistent to MacOS general behaviour when window is closed app is still running. However when I do that, if I click on Dock icon option "Show all windows" it says "No windows available". How can I…
RuLoViC
  • 825
  • 7
  • 23
0
votes
1 answer

How to refresh a QApplication using QWebEngineView every with an schedule period

I'm trying to reload an URL in a given period using PYQT5, QWebEngineView, and schedule as far as I've search the code stops its execution after the app_exec(). So the "while" cicle and "scheduler" never gets executed. as far as i have search…
0
votes
1 answer

Qt5 and Cmake linking QApplication header error

I am trying to link cmake with one of my Qt projects that uses QApplication. I am getting this error when I build the project Cannot open include file: 'QApplication': No such file or directory I am only using QApplication and QWebEngineWidget in…
Noopty
  • 167
  • 2
  • 12
0
votes
0 answers

PyQt4: QTreeView constructor causes crash: QWidget: Must construct a QApplication before a QPaintDevice

I run into a strange behavior, where my QApplication seems not initialize correctly. I have two modules: foo.py and bar.py. bar.py content: module: bar from PyQt4 import QtGui class MyTreeView(QtGui.QTreeView): def __init__(self, name,…
MagSec
  • 346
  • 4
  • 17
0
votes
1 answer

Sending signal to QApplication

I'm sending a signal.CTRL_BREAK_EVENT to a QApplication subprocess and the subprocess's handler manages to catch the signal (and perform some magic before exiting). However, when the signal is sent, it is not processed until I interact with the…
niCk cAMel
  • 869
  • 1
  • 10
  • 26
0
votes
1 answer

Using QApplication with gTest in Linux

I used QApplication objects in gTest in Visual Studio. int argc = 0; char **argv = 0; QMainWindow *window; TEST() { app = new QApplication(argc, argv); window = new QMainWindow(); // Test Execution // Data gathering app.exec(); …
heitho
  • 61
  • 1
  • 7
0
votes
1 answer

must construct QApp before QWidget Pyqt5

I started new PyQt5 programme but I encounter the error "Must construct QApplication before QWidget". I understand the error, but not find where my code constructs my QWidget first. Here's my code: class Main(QWidget): """ Main window """ …
Y.Berthoud
  • 75
  • 8
0
votes
0 answers

Why am I getting the error "QWidget: must construct a QApplication before a widget"?

I get the following error: QWidget: must construct a QApplication before a widget It worked 3 days ago, but now it doesn't work anymore, and I don't know why. What does this error mean? I don't know if I modified something. Here is my…
Omar Krichen
  • 163
  • 1
  • 2
  • 12
0
votes
0 answers

Launching Multiple QApplication within a DLL

I have used this link to get me started, [https://stackoverflow.com/a/11056698/5609063][1] I am trying to create an object which creates its GUI internally, and cleans itself up. I have a call to quit() as well within lets me close the gui out if I…
0
votes
1 answer

Compiling Qt5 App on Raspberry

I'd like to compile a program on my Raspberry Pi 3. I've installed the latest Raspbian and crosscompiled Qt 5.8 as described in this manual and then I've tried to build GST to run it on the board. The compile process seems to finish, however, I've…
Vitalic
  • 1
  • 3
0
votes
1 answer

Find out if app was already initialized?

I wanted to spawn a QWebKit instance in PySide and quickly got a segmentation fault - I forgot to set up an instance of QApplication. Since SIGSEGV is not a good failure mode, is there a way to catch that and throw an exception instead?
d33tah
  • 10,999
  • 13
  • 68
  • 158