Results 1 to 3 of 3

Thread: subclassing QApplication

  1. #1
    Join Date
    Mar 2006
    Posts
    172
    Thanks
    30
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Lightbulb subclassing QApplication

    I have always used a QApplication object in the main function, as is used generally. What I am a bit curious about is this: when and why should one subclass QApplication?

    Thanks

    Nupul

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: subclassing QApplication

    You must subclass QApplication when you want to change the behavior of one or more of its virtual methods.

    Here's an example: http://www.qtcentre.org/forum/showth...0399#post10399

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: subclassing QApplication

    Or if you want to embed the whole application data into one object (for example to avoid global variables). You can then override QCoreApplication::instance() to return your "extended" pointer. And your main() can look like this then:

    Qt Code:
    1. #include "myapplication.h"
    2.  
    3. int main(int argc, char **argv){
    4. MyApplication app(argc, argv);
    5. return app.exec();
    6. }
    To copy to clipboard, switch view to plain text mode 

  4. The following user says thank you to wysota for this useful post:

    nupul (20th April 2006)

Similar Threads

  1. QApplication instance
    By nile.one in forum Qt Programming
    Replies: 9
    Last Post: 5th October 2007, 12:06
  2. Calling QApplication from a Non-QT app?
    By hickscorp in forum Qt Programming
    Replies: 2
    Last Post: 10th April 2007, 22:00
  3. Replies: 2
    Last Post: 16th March 2007, 09:04
  4. qapplication with open(/dev/name,O_RDWR) crashed???
    By ttbug in forum Qt for Embedded and Mobile
    Replies: 2
    Last Post: 16th September 2006, 07:56
  5. Reponsabilities of QApplication and QMainWindow classes
    By yellowmat in forum Qt Programming
    Replies: 4
    Last Post: 4th September 2006, 16:21

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.