Search code examples
c++qtblackberry-10signals-slots

QObject:connect No such slot issue


I have no clue as to why its happening. I have extended QObject and also added the macro Q_OBJECT. Also signal and slot both has same parameter.

I have posted the original question

http://supportforums.blackberry.com/t5/Cascades-Development/Object-connect-No-such-slot-problem/m-p/2486753

This is my hpp file:

/*
 * LocationMonitor.hpp
 *
 *  Created on: Jul 13, 2013
 *      Author: Roland
 */

#ifndef LOCATIONMONITOR_HPP_
#define LOCATIONMONITOR_HPP_

#include <QObject>
#include <QtLocationSubset/qgeopositioninfo.h>
#include <QtLocationSubset/qgeoareamonitor.h>

using namespace Qt;
using namespace QtMobilitySubset;
class GeoNotification;
class LocationMonitor : public QObject
{
    Q_OBJECT
public:
    LocationMonitor(int id,GeoNotification *geoNotification,QVariantList locationList,QVariantList actionList);
    virtual ~LocationMonitor();

public slots:
    void areaEnteredd(QtMobilitySubset::QGeoPositionInfo info);
    void areaExitedd(QtMobilitySubset::QGeoPositionInfo info);

public:
    QGeoAreaMonitor *monitor;
};

#endif /* LOCATIONMONITOR_HPP_ */

This is my cpp file

/*
 * LocationMonitor.cpp
 *
 *  Created on: Jul 13, 2013
 *      Author: Roland
 */

#include "LocationMonitor.hpp"

LocationMonitor::LocationMonitor(int id,GeoNotification *geoNotification,QVariantList locationList,QVariantList actionList):
geoNotification(geoNotification)
{
    monitor = QGeoAreaMonitor::createDefaultMonitor(this);
    QObject::connect(monitor, SIGNAL(areaEntered(QGeoPositionInfo)),this, SLOT(areaEnteredd(QGeoPositionInfo)));
    QObject::connect(monitor, SIGNAL(areaExited(QGeoPositionInfo)),this, SLOT(areaExitedd(QGeoPositionInfo)));
}
LocationMonitor::~LocationMonitor() {}

void LocationMonitor::areaEnteredd(QGeoPositionInfo info)
{
}
void LocationMonitor::areaExitedd(QGeoPositionInfo info)
{
}

API doc link is in here

Thanks.


Solution

  • You need to use the same name everywhere: in the signal declaration, in the slot declaration and in the connect. That is because the connect() mechanism is based on textual comparison.

    As the original signal is declared with only const QGeoPositionInfo & as parameter, you need to set this, and only this, too.

    Here are the declarations you should use:

        // Header
        public slots:
            void areaEnteredd(const QGeoPositionInfo& info);
            void areaExitedd(const QGeoPositionInfo& info);
    
        // CPP
        void LocationMonitor::areaEnteredd(const QGeoPositionInfo& info)
        {
        }
        void LocationMonitor::areaExitedd(const QGeoPositionInfo& info)
        {
        }
        // Connects
        QObject::connect(monitor, SIGNAL(areaEntered(const QGeoPositionInfo&)),this, SLOT(areaEnteredd(const QGeoPositionInfo&)));
        QObject::connect(monitor, SIGNAL(areaExited(const QGeoPositionInfo&)),this, SLOT(areaExitedd(const QGeoPositionInfo&)));
    

    Note that you'll have to use the QtMobilitySubset namespace in your header, which is bad. You can limit the scope to what you really need: using ::QtMobilitySubset::QGeoPositionInfo; instead of a full using namespace QtMobilitySubset;.