You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Thursday, March 24th 2005, 9:59pm

Subclassing QDir

I'd like to create the ZDir class to add facilities to QDir.

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
//header file
#ifndef ZDIR_H
#define ZDIR_H
#include <qdir.h>
class ZDir : public QDir
{
	Q_OBJECT
public:
	ZDir();
};
#endif
//implementation file
#include "zdir.h"
#include <qdir.h>


As such, the implementation file does not compile because the compiler does not recognize Q_OBJECT. It asks for an ";" before "public" and wonders about its type. Without Q_OBJECT, there is however no problem.
Could anyone explain why it is so?
Many thanks

jacek

Master

  • "jacek" is male

Posts: 2,729

Location: Warsaw, Poland

  • Send private message

2

Thursday, March 24th 2005, 10:07pm

RE: Subclassing QDir

Quoted

Originally posted by jcr
Could anyone explain why it is so?

QDir doesn't inherit QObject.

3

Thursday, March 24th 2005, 10:29pm

RE: Subclassing QDir

Better approaches would therefore be to
1. inherit QObject and add a public QDir member
2. inherit both QObject and QDir
thanks

jacek

Master

  • "jacek" is male

Posts: 2,729

Location: Warsaw, Poland

  • Send private message

4

Thursday, March 24th 2005, 10:54pm

RE: Subclassing QDir

Quoted

Originally posted by jcr
Better approaches would therefore be to
1. inherit QObject and add a public QDir member
2. inherit both QObject and QDir

If this is a question, then answer depends on what you want to do.