QObject:连接没有这样的插槽问题。

时间:2021-06-24 18:48:49

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.

我不知道为什么会发生这种事。我扩展了QObject并添加了宏Q_OBJECT。信号和槽都具有相同的参数。

I have posted the original question

我已经发布了最初的问题。

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

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

This is my hpp file,

这是我的hpp文件,

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

#ifndef LOCATIONMONITOR_HPP_
#define LOCATIONMONITOR_HPP_

#include 
#include 
#include 

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

这是我的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 doc link is in here

API doc链接在这里。

Thanks.

谢谢。

2 个解决方案

#1


7  

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.

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

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

由于原始信号只使用const QGeoPositionInfo和As参数声明,所以您需要设置这个,并且只需要设置这个。

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;.

注意,您必须在头中使用qtmobility子集名称空间,这很糟糕。您可以将范围限制为您真正需要的范围:使用:qtmobility子集::QGeoPositionInfo;而不是完全使用名称空间qtmobility子集;

#2


2  

You're declaring your slots to take this variable: QtMobilitySubset::QGeoPositionInfo &info but on connect specifying they take QGeoPositionInfo & instead. As you've declared them with QtMobilitySubset::QGeoPositionInfo & you need to have the QtMobilitySubset on your connect statement.

您正在声明您的插槽以获取该变量:qtmobility子集::QGeoPositionInfo和info,但在连接上指定它们使用QGeoPositionInfo &相反。正如您已经使用qtmobility子集所声明的::QGeoPositionInfo &您需要在connect语句中拥有qtmobility子集。

#1


7  

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.

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

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

由于原始信号只使用const QGeoPositionInfo和As参数声明,所以您需要设置这个,并且只需要设置这个。

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;.

注意,您必须在头中使用qtmobility子集名称空间,这很糟糕。您可以将范围限制为您真正需要的范围:使用:qtmobility子集::QGeoPositionInfo;而不是完全使用名称空间qtmobility子集;

#2


2  

You're declaring your slots to take this variable: QtMobilitySubset::QGeoPositionInfo &info but on connect specifying they take QGeoPositionInfo & instead. As you've declared them with QtMobilitySubset::QGeoPositionInfo & you need to have the QtMobilitySubset on your connect statement.

您正在声明您的插槽以获取该变量:qtmobility子集::QGeoPositionInfo和info,但在连接上指定它们使用QGeoPositionInfo &相反。正如您已经使用qtmobility子集所声明的::QGeoPositionInfo &您需要在connect语句中拥有qtmobility子集。