How to use slots in the namespace class
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
Code:
namespace CCentralImply
{
void func();
void func_one();
private slots: //At this Line it shows error [B]expected declaration[/B]
slot_name();
}
Thanks & regards,
Rohith.G
Re: How to use slots in the namespace class
Declare using namespace CCentralImply Where ever u want to access namespace modules....
Re: How to use slots in the namespace class
Namespaces are not classes so they cannot have slots.
Re: How to use slots in the namespace class
Re: How to use slots in the namespace class
Quote:
Originally Posted by
Vikram.Saralaya
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,
_
Re: How to use slots in the namespace class
Quote:
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():
Code:
void someFunction();
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.
Re: How to use slots in the namespace class
Quote:
Originally Posted by
d_stranz
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,
_