Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 01-15-2004, 12:09 PM   #1
Senior Member
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
Inheriting class members (Qt C++, QApplication class)

I have done a few small things with Qt and last week I decide I was going to try to do some serious Qt programming to get a better feel for how it all works. I have succesfully made my own widgets extending the QWidget class.

I am trying to write a new class call wirelessApp. It is an extension of QApplication.

I have no constructor so I assumed it would inherit the constructor from QApplication yet I get the following error when I make an instance of this class:

wirelessapp.h:27: base `QApplication' with only non-default constructor in class without a constructor

Usually when you create an instance of QApplication you would do something like this:

QApplication myApp(argc, argv) ;
Passing in the argc and argv from the main function (ie the command line options) because there are some common command line options that work in every Qt program. Now on mine I have a class that is declared:class wirelessApp : public QApplication

To get an instance of that I assumed wirelessApp wApp(argc,argv); would invoke the same constructor and I could then be free to use the new functionality I added to this particular class as well as all the functions from QApplication. However the compiler error is really confusing me, any ideas?
Old 01-15-2004, 12:45 PM   #2
Registered: Jan 2004
Posts: 40

Rep: Reputation: 15
Inherited classes herits constructors from super classes but it only construct the superclass part of the class (not the part of the subclass that still must be constructed) so you must write a new one. If the super class has défault constructor (without parameters) then it is assumed that this one will be used.

Construction of subclasses is done by following the hierarchy if you have


It construct QObject then QApllication then WirelessApp so you must invoke a super class constructor (this is done because maybe you have private members in QApplication that must be initialized).

So simply do a constructor in your subclass that invoke the superclass constructor this can be done like this

WirelessApp(argv,argc): QApplication(argv,argc) {
//Your constructor code here.

Hope this help and was understandable.
Old 01-15-2004, 12:52 PM   #3
Senior Member
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Original Poster
Rep: Reputation: 67
yes, helps a lot, thanks.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Implementing a vector class from a list class purefan Programming 9 04-14-2005 11:48 PM
PHP: how to use a method from a class in the same class ldp Programming 5 09-17-2004 10:52 AM
BlackBox.class & VerifierBug.class virus ??? dalek Linux - Security 4 02-29-2004 09:55 AM
can't use protected inner class when inheriting the outer Dominik Programming 6 02-02-2004 02:12 AM
c++ : regarding (inheritence)base class and derived class edreddy Programming 6 07-31-2002 07:33 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:35 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration