0

我不知道为什么会这样。我已经扩展QObject并添加了宏Q_OBJECT。此外,信号和插槽都具有相同的参数。

我已经发布了原始问题

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

这是我的 hpp 文件:

/*
 * 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_ */

这是我的 cpp 文件

/*
 * 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 文档链接在这里

谢谢。

4

2 回答 2

7

您需要在任何地方使用相同的名称:在信号声明中、插槽声明中和连接中。那是因为该connect()机制是基于文本比较的。

由于原始信号仅使用const QGeoPositionInfo &作为参数声明,因此您需要设置这个,也只有这个。

以下是您应该使用的声明:

    // 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&)));

请注意,您必须QtMobilitySubset在标题中使用名称空间,这很糟糕。您可以将范围限制在您真正需要的范围内:using ::QtMobilitySubset::QGeoPositionInfo;而不是完整的using namespace QtMobilitySubset;.

于 2013-07-19T12:18:34.760 回答
2

您正在声明您的插槽采用此变量:QtMobilitySubset::QGeoPositionInfo &info但在connect指定它们时采用QGeoPositionInfo &。正如您已经声明它们一样,QtMobilitySubset::QGeoPositionInfo &您需要QtMobilitySubset在您的connect声明中添加。

于 2013-07-19T10:21:02.833 回答