Results 1 to 5 of 5

Thread: Newbie: Subclassing QObject

  1. #1
    Join Date
    Apr 2010
    Posts
    77
    Thanks
    10
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Newbie: Subclassing QObject

    Hi
    I want to create several classes as subclasses of QObject so that I can use the QPointer smart pointer.

    But when I subclass a Contacts class and build the code, I get this error:

    "QObject is an inaccessible base of Contacts".

    The constructor is simple enough:
    Contacts::Contacts()
    :QObject()
    {

    }

    What am I missing?

    Cheers
    Jeff

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Newbie: Subclassing QObject

    Qt Code:
    1. class Contacts : public QObject
    2. {
    3. Q_OBJECT
    4. public:
    5. Contacts(QObject* parent = 0);
    6. };
    7.  
    8. Contacts::Contacts(QObject* parent) : QObject(parent)
    9. {
    10. //...
    11. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Apr 2010
    Posts
    77
    Thanks
    10
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Newbie: Subclassing QObject

    Hi Lykurg

    That didn't help.
    Here is the relavant code:

    Contacts.h file

    #ifndef CONTACTS_H
    #define CONTACTS_H

    #include <QObject>
    #include <QString>

    #include "JBObjectTemplate.h"

    class Contacts : QObject, JBObjectTemplate
    {
    Q_OBJECT

    public:
    Contacts(QObject* parent = 0);
    ~Contacts();

    etc.

    Contacts.cpp file

    #include "Contacts.h"

    Contacts::Contacts(QObject* parent)
    :QObject(parent), JBObjectTemplate()
    {

    }

    Contacts::~Contacts()
    {

    }
    etc.

    main.cpp file
    #include <iostream>
    #include <QPointer>
    #include "Contacts.h"

    using namespace std;

    int main()
    {
    QPointer<Contacts> aContact = new Contacts();
    //Contacts *aContact = new Contacts();
    aContact->setContactID(2);
    etc.

    Any help really appreciated.
    Thanks, Jeff

  4. #4
    Join Date
    Aug 2009
    Location
    Greece, Chania
    Posts
    63
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Newbie: Subclassing QObject

    Isn't it class Contacts : public QObject, public JBObjectTemplate
    instead of class Contacts : QObject, JBObjectTemplate ?
    Misha R.evolution - High level Debugging IDE

    Programming is about 2 basic principles: KISS and RTFM!!!

  5. #5
    Join Date
    Apr 2010
    Posts
    77
    Thanks
    10
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Newbie: Subclassing QObject

    Hi Archimedes

    Nice one. Thats it!
    It's been over 6 years since I programmed in C++.
    The last 6 years has been Objective C which I would have to say is far more elegant.

    I can see it's going to take a little while to get myself back up to speed.

    Cheers
    Jeff

Similar Threads

  1. Subclassing QFontDialog
    By fsoltanshahi in forum Qt Programming
    Replies: 0
    Last Post: 23rd October 2008, 16:29
  2. Replies: 1
    Last Post: 31st October 2007, 14:14
  3. subclassing QApplication
    By nupul in forum Newbie
    Replies: 2
    Last Post: 19th April 2006, 19:29
  4. Subclassing
    By joseph in forum Newbie
    Replies: 1
    Last Post: 25th February 2006, 14:06
  5. subclassing/inheritance QObject problem
    By cbeall1 in forum Qt Programming
    Replies: 12
    Last Post: 13th February 2006, 17:49

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
  •  
Qt is a trademark of The Qt Company.