所以我在app.cpp中有一个函数,它是在hpp文件中定义的;
class App : public QObject
{
//Some stuff here
public:
App();
void registerToServer(QString apiURL, QUrl params);
我正在尝试从另一个 .cpp 文件中调用该函数。我在 .hpp 文件中完成了以下操作;
App m_app;
然后是我的电话;
m_app.registerToServer(etc etc)
但是我不断收到 App '没有定义类型'的错误
谢谢
编辑:App.hpp 文件;
#ifndef APP_HPP
#define APP_HPP
#include "service/ConfigurationService.hpp"
#include "service/PushNotificationService.hpp"
#include <bb/cascades/GroupDataModel>
#include <bb/system/InvokeManager>
#include <bb/system/SystemCredentialsPrompt>
#include <QtCore/QtCore>
#include <QString>
#include <bb/cascades/Application>
#include <bb/device/HardwareInfo>
#include <bb/cascades/AbstractPane>
#include <bps/deviceinfo.h>
#include <bps/netstatus.h>
#include <bps/locale.h>
class PushContentController;
class App : public QObject
{
Q_OBJECT
QString getDevicePIN();
// The data model that contains all received pushes
Q_PROPERTY(bb::cascades::GroupDataModel* model READ model CONSTANT)
Q_PROPERTY(bool modelIsEmpty READ modelIsEmpty NOTIFY modelIsEmptyChanged)
// The title and body text for the notification dialog
Q_PROPERTY(QString notificationTitle READ notificationTitle NOTIFY notificationChanged)
Q_PROPERTY(QString notificationBody READ notificationBody NOTIFY notificationChanged)
// The title and body text for the activity dialog
Q_PROPERTY(QString activityDialogTitle READ activityDialogTitle NOTIFY activityDialogChanged)
Q_PROPERTY(QString activityDialogBody READ activityDialogBody NOTIFY activityDialogChanged)
// The controller object for the push content page
Q_PROPERTY(PushContentController* currentPushContent READ currentPushContent CONSTANT)
// The configuration provider application ID.
Q_PROPERTY(QString appId READ appId WRITE setAppId NOTIFY appIdChanged)
// The configuration Push Proxy Gateway(PPG) URL.
Q_PROPERTY(QString ppgUrl READ ppgUrl WRITE setPpgUrl NOTIFY ppgUrlChanged)
// The configuration push initiator URL.
Q_PROPERTY(QString pushInitiatorUrl READ pushInitiatorUrl WRITE setPushInitiatorUrl NOTIFY pushInitiatorUrlChanged)
// The configuration 'useSdk' value.
Q_PROPERTY(bool useSdk READ useSdk WRITE setUseSdk NOTIFY useSdkChanged)
// The configuration 'launchApplicationOnPush' value.
Q_PROPERTY(bool launchApplicationOnPush READ launchApplicationOnPush WRITE setLaunchApplicationOnPush NOTIFY launchApplicationOnPushChanged)
// The configuration 'usingPublicPpg' value.
Q_PROPERTY(bool usePublicPpg READ usePublicPpg WRITE setUsePublicPpg NOTIFY usePublicPpgChanged)
public:
App();
void registerToServer(QString apiURL, QUrl params);
QSettings newConfigSettings;
/**
* Saves the Configuration to the persistent store.
*/
Q_INVOKABLE void saveConfiguration();
/**
* Loads the Configuration from the persistent store.
*/
Q_INVOKABLE void loadConfiguration();
/**
* Returns a value that indicates whether or not the Configuration settings are valid.
*
* @return true if valid; false otherwise
*/
Q_INVOKABLE bool validateConfiguration();
/**
* Calls the push service create channel
*/
Q_INVOKABLE void createChannel();
/**
* Calls the push service destroy channel
*/
Q_INVOKABLE void destroyChannel();
Q_INVOKABLE void deletePush(const QVariantMap &item);
Q_INVOKABLE void deleteAllPushes();
Q_INVOKABLE void markAllPushesAsRead();
Q_INVOKABLE void changeConnectionText(const QString newText);
/**
* Marks the passed push as current one and prepares the controller
* object of the PushContentPage.
*/
Q_INVOKABLE void selectPush(const QVariantList &indexPath);
Q_INVOKABLE void sendSms(const QString &messageText, const QStringList &phoneNumbers);
public Q_SLOTS:
void onCreateSessionCompleted(const bb::network::PushStatus &status);
void onCreateChannelCompleted(const bb::network::PushStatus &status, const QString &token);
void onDestroyChannelCompleted(const bb::network::PushStatus &status);
void onRegisterToLaunchCompleted(const bb::network::PushStatus &status);
void onUnregisterFromLaunchCompleted(const bb::network::PushStatus &status);
void onRegisterPromptFinished(bb::system::SystemUiResult::Type value);
void onUnregisterPromptFinished(bb::system::SystemUiResult::Type value);
void onPIRegistrationCompleted(int code, const QString &description);
void onPIDeregistrationCompleted(int code, const QString &description);
void onInvoked(const bb::system::InvokeRequest &request);
void onSimChanged();
void onPushTransportReady(bb::network::PushCommand::Type command);
void quit();
private Q_SLOTS:
void httpFinished(QNetworkReply* reply);
Q_SIGNALS:
void modelIsEmptyChanged();
void notificationChanged();
void activityDialogChanged();
void appIdChanged();
void ppgUrlChanged();
void pushInitiatorUrlChanged();
void useSdkChanged();
void launchApplicationOnPushChanged();
void usePublicPpgChanged();
void openActivityDialog();
void closeActivityDialog();
private:
PushDAO m_pushDAO;
// A helper function to initialize the push session
void initializePushSession();
bool validateUser(const QString &dialogTitle, const QString &username, const QString &password);
void loadUser();
void setPromptDefaultText(bb::system::SystemCredentialsPrompt* prompt,const QString &username, const QString &password);
void pushNotificationHandler(bb::network::PushPayload &pushPayload);
void showDialog(const QString &title, const QString &message);
void openActivityDialog(const QString &title, const QString &message);
void onNetworkStatusUpdated ( bool connectionStatus, QString interfaceType );
// The accessor methods of the properties
bb::cascades::GroupDataModel* model() const;
bool modelIsEmpty() const;
QString notificationTitle() const;
QString notificationBody() const;
QString activityDialogTitle() const;
QString activityDialogBody() const;
PushContentController* currentPushContent() const;
QString appId() const;
void setAppId(const QString &appId);
QString ppgUrl() const;
void setPpgUrl(const QString &ppgUrl);
QString pushInitiatorUrl() const;
void setPushInitiatorUrl(const QString &pushInitiatorUrl);
bool useSdk() const;
void setUseSdk(bool value);
bool launchApplicationOnPush() const;
void setLaunchApplicationOnPush(bool launchAppOnPush);
bool usePublicPpg() const;
void setUsePublicPpg(bool usingPublicPpg);
QString getDeviceIMEI();
// The manager object to react to invocations
bb::system::InvokeManager *m_invokeManager;
// The credentials dialog to register to the push service
bb::system::SystemCredentialsPrompt *m_registerPrompt;
// The credentials dialog to unregister from the push service
bb::system::SystemCredentialsPrompt *m_unregisterPrompt;
// The wrapper classes for loading/storing configuration values
ConfigurationService m_configurationService;
Configuration m_configuration;
// The wrapper class for the current user
User m_user;
PushNotificationService m_pushNotificationService;
bool m_shouldRegisterToLaunch;
bool m_shouldUnregisterFromLaunch;
// The controller object for the push content page
PushContentController* m_pushContentController;
// The property values
bb::cascades::GroupDataModel *m_model;
QString m_notificationTitle;
QString m_notificationBody;
QString m_activityDialogTitle;
QString m_activityDialogBody;
QString m_appId;
QString m_ppgUrl;
QString m_pushInitiatorUrl;
QString m_connectionStatus;
bool m_useSdk;
bool m_launchApplicationOnPush;
bool m_usePublicPpg;
QString device_pin;
QNetworkAccessManager m_accessManager;
UserDAO m_userDAO;
QNetworkReply *m_reply;
ConfigurationDAO m_testConfig;
};
#endif
RegisterToServer 函数。
void App::registerToServer(QString apiURL, QUrl params)
{
QUrl serviceUrl = QUrl(apiURL);
QByteArray postData;
postData = params.encodedQuery();
QNetworkAccessManager *networkManager = new QNetworkAccessManager(this);
networkManager->post(QNetworkRequest(serviceUrl),postData);
// Connect to the reply finished signal.
connect(networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(httpFinished(QNetworkReply*)));
}