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

cannot create a qwidget without qapplication although qapplication is included

Following error has showed up all of a sudden: QWidget: Cannot create a QWidget without QApplication It was working fine and I have QApplication included and a QApplication object declared before MainWindow, but the error is still there. #include…
Ness
  • 158
  • 1
  • 12
1
vote
2 answers

When should I use qApp->setProperty on Qt

I'm not finding, on the Qt documentation, a section explaining about the qApp->setProperty() option (it is probably there, but I can't find it). Can someone explain to me basically how it works and when should I use it? I'm asking it because I need…
KelvinS
  • 2,870
  • 8
  • 34
  • 67
1
vote
1 answer

Totally deleting the QApplication Instance and recreating it in another thread

How can I totally remove the QApplication instance, so it can be possible to recreate it again in a sheared library. If I have such a following code: int main(int argc, char ** argv) { QApplication *app = new QApplication(argc, argv); MyWindow…
Khaled
  • 59
  • 1
  • 12
1
vote
1 answer

prevent QApplication::exec from blocking main thread

I have a visual c++ program which creates multiple GUI on the main thread. I want to show a QWidget alongside all the other GUI. Currently, if I call QApplication.exec(), it blocks the main thread until I close the window. Is there any way to…
Vasundhara Mehta
  • 278
  • 2
  • 3
  • 16
1
vote
2 answers

QThread and implementation of notify

What to look out for when reimplementing notify function in multi threaded Qt application? This is an example implementation. Currently there are no errors, but I am worried that an error could arise since multi threading in Qt uses signal slot for…
Anže
  • 181
  • 8
1
vote
0 answers

How can I make a loop with PyQt4?

I'm trying to make a program that opens a window every 10 seconds and waits for the user to close it, in order to restart counting the next 10 seconds. I have the following code: class Window(QtGui.QWidget): def __init__(self): …
1
vote
0 answers

How to avoid the warning “QApplication was not created in main() thread” without having access to the main thread?

I wrote code in PyQt4 that scrapes a website and its inner frames. import sys, signal from PyQt4 import QtGui, QtCore, QtWebKit class Sp(): def save(self, ok, frame=None): if frame is None: print ('main-frame') frame =…
yuval
  • 2,848
  • 4
  • 31
  • 51
1
vote
1 answer

Ungraceful / kill Qt application when event loop is not started

How can I terminate a running Qt application (QCoreApplication) when exit does not work because the event loop is not yet started. http://doc.qt.io/qt-5/qcoreapplication.html#exit After this function has been called, the application leaves the…
Horst Walter
  • 13,663
  • 32
  • 126
  • 228
1
vote
2 answers

How to exit a "game" in Qt when health is 0

I'm quite new to Qt, but I got into it to start experimenting with making 2D games. I've got a extremely rough and simple game started, but I have an issue. Whenever the health gets to 0, the game doesn't end. I just want to know how to end the game…
Jarrod A.
  • 93
  • 1
  • 9
1
vote
3 answers

QApplication Within A Shared Library Event Loop Issues

I'm trying to use QWebPage in a shared library, which means I have to have QApplication in there to get a GUI context for it to run in. I've built my code up to get this in place, however as soon as I run qApp->exec() the Event Loop completely…
Nicholas Smith
  • 11,642
  • 6
  • 37
  • 55
1
vote
3 answers

QT: how to exit application and close UI

I tried to use qApp->exit() to exit application and close UI. but I failed the UI is still there after qApp->exit() executed. Anyone can help to figure out why? thanks a lot. #include "clsDownloadUpdateList.h" #include #include…
Nicholas Yu
  • 333
  • 1
  • 5
  • 7
1
vote
4 answers

R section not working

If i open the R section its shows the Javascript Alert - 127.0.0.1 box likes this,

R encountered a fatal error.

The session was terminated. In the terminal its shows, aarthika@aarthika-HP-406-G1-MT:~$ rstudio load glyph failed err=6…
Aarthika
  • 101
  • 11
1
vote
2 answers

Why winmain parameters doesn't match to each other?

Why QApp constructor fails with WinMain parameters? int CALLBACK WinMain(HINSTANCE, HINSTANCE, LPTSTR _lpCmdLine, int _nShowCmd) { QApplication app(_nShowCmd, & _lpCmdLine); And here it fail with exception: Exception at adress 0x0F3621DC…
user453575457
  • 464
  • 6
  • 21
1
vote
1 answer

Qt5 How to call QApplication from another class?

Hi I'm writing multilanguage application in Qt5. I want to access QApplication a(argc, argv); localised in main.cpp from my Settings class. I need this to perform 2 commands: a.installTranslator(); a.removeTranslattor(); when I'm trying to do do…
km2442
  • 779
  • 2
  • 11
  • 31
1
vote
1 answer

PyQt thread still running after window closed

When I close an application window in PyQt the console is still left running in the background and python.exe process is present until I close the console. I think the sys.exit(app.exec_()) is not able to operate properly. Mainscript (which opens…
Prof
  • 657
  • 1
  • 14
  • 24