PDA

View Full Version : How to use slots in the namespace class



gunturrohith
7th December 2015, 10:12
Hi,

I am trying to use the slots in a class that is define by using the word namespace in the Qt Creator but it is showing an error "Needs an declaration"
Is it possible to do so the code that i have written is



namespace CCentralImply
{
void func();
void func_one();

private slots: //At this Line it shows error expected declaration
slot_name();
}


Thanks & regards,
Rohith.G

mandlakoteswar2011
7th December 2015, 10:20
Declare using namespace CCentralImply Where ever u want to access namespace modules....

Vikram.Saralaya
7th December 2015, 10:38
Namespaces are not classes so they cannot have slots.

mandlakoteswar2011
7th December 2015, 10:40
Y ur Declaring Slots...?

anda_skoa
7th December 2015, 10:53
Namespaces are not classes so they cannot have slots.
Exactly.

Slots can only be declared in QObject derived classes.

However, Qt5's function pointer based connect() can connect to functions that are not slots.

Cheers,
_

d_stranz
7th December 2015, 19:09
However, Qt5's function pointer based connect() can connect to functions that are not slots.

In addition, there are versions of this connect() that do not require a QObject receiver pointer. From the docs for QObject::connect():



void someFunction();
QPushButton *button = new QPushButton;
QObject::connect(button, &QPushButton::clicked, someFunction);


So potentially if the code in the original post was cleaned up to proper C++ syntax, then the "someFunction" above could be prefaced by the namespace.

anda_skoa
7th December 2015, 19:20
In addition, there are versions of this connect() that do not require a QObject receiver pointer.
Yes, indeed!

I thought that would be kind of implicit by me writing "function" instead of "method" but it made sense to point this out explicitly :)

Cheers,
_