[Qt-interest] Qt, C++ Namespaces, and Signals/Slots
BRM
bm_witness at yahoo.com
Thu Jun 24 17:19:21 CEST 2010
I am moving around some definitions from a Qt-only header set to a shared Qt and Standard C++ header sets.
In the new header sets I am utilizing C++ namespaces. Updating everything seems to have gone fine, but thus far I've only tested using MSVC.
Presently this just applies for a series of enums, and a few structures as well; a number of these get used in signals and slots.
Not every use of the types warrants the implementation file having a using namespace for the namespace these are stored in - and I will have multiple levels of namespaces.
What I am curious about is that in one case the function definitions for the signals/slots included the namespaces;
however, I didn't put the namespaces in the connect() statement - or the SIGNAL()/SLOT() sub-parts of it; yet, Qt seems to have made the right connections, and allowed it.
I expected I would have to update the SIGNAL()/SLOT() to have the namespace parts in it too. Presently I have only noticed this for some standard C++ enums that I reference.
But I am wondering if this is by design or some fluke - e.g. can I rely on this, or should I really namespace the parameters?
Where I have used qRegisterMetaType<>() to register something I did add in the namespace referencing, but I have not done that in all cases.
Example:
namespace X {
namespace Y {
enum anEnum {
anEnumValue1=0,
anEnumValue2,
...
};
}
}
class myQtClassA : QObject {
...
Q_SIGNALS:
void someSignal(X:Y:anEnum...);
...
};
class myQtClassB: QObject {
...
public Q_SLOTS:
void someSlot(X:Y:anEnum);
...
};
myQtClassB::someFunction(myQtClassA* _a){
...
connect(_a,SIGNAL(someSignal(anEnum)),this,SLOT(someSlot(anEnum));
...
}
TIA,
Ben
More information about the Qt-interest-old
mailing list