enum as parameter in QSignal not working?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

enum as parameter in QSignal not working?

Gabriel Voicu
I'm trying to do, in gpssearchview.cpp, something like:

connect(d->mapSearchWidget, SIGNAL(signalMouseModeChanged(KMap::MouseMode)),
             this, SLOT(slotMouseMode Changed(KMap::MouseMode)));

and when I run digikam, in Konsole says:
No such signal KMap::KMapWidget::signalMouseModeChanged(KMap::MouseMode) in ./gpssearchview.cpp

KMap::MouseMode is an enum that holds the mouse modes in libkmap:

enum MouseMode{
    MouseModePan,
    MouseModeSelection,
    MouseModeZoom,
    MouseModeFilter,
    ...};

If I remove the parameter of the signal ( I put signalMouseModeChanged() instead of signalMouseModeChanged(KMap::MouseMode)), all works and the signal is emitted right. QSignal doesn't admit enum parameters in signals?

Gabriel

_______________________________________________
Digikam-devel mailing list
[hidden email]
https://mail.kde.org/mailman/listinfo/digikam-devel
Reply | Threaded
Open this post in threaded view
|

Re: enum as parameter in QSignal not working?

Johannes Wienke-2
Hey

On 10/20/2010 10:35 AM, Gabriel Voicu wrote:

> I'm trying to do, in gpssearchview.cpp, something like:
>
> connect(d->mapSearchWidget, SIGNAL(signalMouseModeChanged(KMap::MouseMode)),
>              this, SLOT(slotMouseMode Changed(KMap::MouseMode)));
>
> and when I run digikam, in Konsole says:
> No such signal KMap::KMapWidget::signalMouseModeChanged(KMap::MouseMode) in
> ./gpssearchview.cpp
>
> KMap::MouseMode is an enum that holds the mouse modes in libkmap:
>
> enum MouseMode{
>     MouseModePan,
>     MouseModeSelection,
>     MouseModeZoom,
>     MouseModeFilter,
>     ...};
Did you try it with a const ref? If this does also not work you can of
course use int ant cast the enums, but that would be ugly.

Regards,
Johannes


_______________________________________________
Digikam-devel mailing list
[hidden email]
https://mail.kde.org/mailman/listinfo/digikam-devel

signature.asc (270 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: enum as parameter in QSignal not working?

Marcel Wiesweg
In reply to this post by Gabriel Voicu
Hi,

I have had problems when using enums for signals, and I have had problems when
using namespace-qualified types for signals.

Have a look at the section "Enums and Typedefs Must Be Fully Qualified for
Signal and Slot Parameters", http://doc.qt.nokia.com/4.6/moc.html
maybe it needs to have the namespace in the .h file.

You'll see some places where I have used "int" parameters in signals.
It's a bit ugly, but works reliably.

Marcel
_______________________________________________
Digikam-devel mailing list
[hidden email]
https://mail.kde.org/mailman/listinfo/digikam-devel
Reply | Threaded
Open this post in threaded view
|

Re: enum as parameter in QSignal not working?

Gabriel Voicu
On Wed, Oct 20, 2010 at 12:26 PM, Marcel Wiesweg <[hidden email]> wrote:
Hi,

I have had problems when using enums for signals, and I have had problems when
using namespace-qualified types for signals.

Have a look at the section "Enums and Typedefs Must Be Fully Qualified for
Signal and Slot Parameters", http://doc.qt.nokia.com/4.6/moc.html
maybe it needs to have the namespace in the .h file.


Thank you, guys,

It worked! In kmap_widget class, I declared the signal

void signalCurrentMouseModeChanged(KMap::MouseMode currentMouseMode) instead of 
void signalCurrentMouseModeChanged(MouseMode currentMouseMode). 
It's pretty funny that QObject::connect compares the two objects literally, but anyway, it's good to know for the future!

Have a nice day,
Gabriel

_______________________________________________
Digikam-devel mailing list
[hidden email]
https://mail.kde.org/mailman/listinfo/digikam-devel
Reply | Threaded
Open this post in threaded view
|

Re: enum as parameter in QSignal not working?

Marcel Wiesweg

> It's pretty funny that QObject::connect compares the two objects literally,
> but anyway, it's good to know for the future!

Yes. The SIGNAL / SLOT macros convert its parameter to a string constant,
QObject::connect takes const char*.
The string is then parsed by QMetaObject::normalizedSignature, removing spaces
etc.
The great advantage of this approach is that it works with DBus, QtScript, QML
etc. The disadvantage is that connect arguments are not checked by the
compiler - I manage again and again to include parameter names in connect.

Marcel
_______________________________________________
Digikam-devel mailing list
[hidden email]
https://mail.kde.org/mailman/listinfo/digikam-devel