View Full Version : Newbie: Subclassing QObject
Jeffb
26th April 2010, 08:30
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
Lykurg
26th April 2010, 09:02
class Contacts : public QObject
{
Q_OBJECT
public:
Contacts(QObject* parent = 0);
};
Contacts::Contacts(QObject* parent) : QObject(parent)
{
//...
}
Jeffb
26th April 2010, 12:48
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
Archimedes
26th April 2010, 13:15
Isn't it class Contacts : public QObject, public JBObjectTemplate
instead of class Contacts : QObject, JBObjectTemplate ?
Jeffb
26th April 2010, 13:30
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
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.