PDA

View Full Version : doubts regarding QT



sudheer168
21st September 2009, 14:20
Hi every body ,I am having some doubts regarding QT

Q. If i create two objects of QApplication what will happen? Why shouldn't i use two?

Q.In Gui application I created on mainwindow and excuted in main.cpp .Then which one is parent I mean QApplication or Mainwindow.

So please help me.

regards,
sudheer.

ChrisW67
23rd September 2009, 09:02
Q. If i create two objects of QApplication what will happen? Why shouldn't i use two?
I cannot think what you could hope to achieve by doing this. From the docs:

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. For non-GUI Qt applications, use QCoreApplication instead, as it does not depend on the QtGui library.
Attempting to allocate a second instance will probably just return a pointer to the existing one. If you really want to know what will happen then try it.

Q.In Gui application I created on mainwindow and excuted in main.cpp .Then which one is parent I mean QApplication or Mainwindow.
Parent of what?

The QMainWindow will not have a QWidget parentWidget(), but may have a QObject parent() depending on how the object was created. The QMainWindow will be the parentWidget() of its central widget, and may be the parent() to QObjects (its subordinate widgets and possibly other stuff).

The QApplication object exists to provide a lot of event handling and general set up/tear down facilities for the application as a whole. It may be the parent to QObjects (including your QMainWindow). It is not a parent in the GUI widget hierarchy... it's not a QWidget.