PDA

View Full Version : No static version of a QFileSystemWatcher/QObject possible?



youkai
6th September 2008, 11:00
Hello. :)

This is a simplified version of the corresponding header file:

#ifndef QU_H_
#define QU_H_

#include <QObject>
#include <QFileSystemWatcher>

class QU: QObject {
Q_OBJECT
public:
QU(QObject *parent = 0);
static QFileSystemWatcher Watcher;
};

#endif /*QU_H_*/
And here the source file (QU.cpp):

#include "QU.h"

QFileSystemWatcher QU::Watcher = QFileSystemWatcher();
QU::QU(QObject *parent): QObject(parent) {}

Well, the initialization of that static member variable is necessary, because otherwise there will be a "undefinied reference to" in the linker.

But I cannot compile the QU.cpp. The error:

QU.cpp: In copy constructor `QFileSystemWatcher::QFileSystemWatcher(const QFileSystemWatcher&)':
../../../../Tools/Qt/4.3.5/include/QtCore/../../src/corelib/kernel/qobject.h:292: error: `QObject::QObject(const QObject&)' is private
QU.cpp:230: error: within this context

What's going on? A static version of a QDir object works fine...

Edit: Well, QDir() is not derived from QObject. Could it be that no QObject could be static because of the signal/slot concept?

jacek
6th September 2008, 15:10
The error says that you can't copy QObjects, not that it can't be static.

Try:
QFileSystemWatcher QU::Watcher;