Pregunta

I have declared QOBJECT macro but still its calling the function without passing the QObject object

Here is my code keyusermanagertest.cpp

#define private public
#define protected public
#include "keyusermanagertest.h"
#include "storageusermanager.h"
#include "keyusermanager.h"
#include "alkuser.h"
#undef protected
#undef private

#include <QDebug>
#include <QtTest/QtTest>

QTEST_MAIN(KeyUserManagerTest)

void KeyUserManagerTest::init()
{

}

void KeyUserManagerTest::cleanup()
{
}

void KeyUserManagerTest::test_initialization()
{
// Already tested under BackendTest::test_initialization()

}

void KeyUserManagerTest::settersAndGetters()
{
    AlkUser userInfo;
    QString user="Puneet Goyal";
    StorageUserManager* storageuser=new StorageUserManager();
    KeyUserManager* keyuser=new KeyUserManager(storageuser);
    keyuser->updateUserData(user,userInfo);
    qDebug()<<"UPDATION DONE!!!!";
// Now setting the rest of the details for user Puneet Goyal using AlkUser Object

    userInfo.setName("Puneet");
    userInfo.setContact("21897121");
    userInfo.setType("savings");
    userInfo.setAccount("123456789");   
    userInfo.setAmount("100000");

// Now retrieving all the user details using KeyUserManager Object
    QVariant vari=keyuser->getUserInfo("Puneet Goyal");

}

keyusermanagertest.h

#ifndef KEYUSERMANAGERTEST_H
#define KEYUSERMANAGERTEST_H

#include <QtCore/QObject>

class KeyUserManager;

class KeyUserManagerTest : public QObject
{
  Q_OBJECT

private slots:

  void init();
  void cleanup();
  void test_initialization();
  void settersAndGetters();
};

#endif

Its compile output is as follows" /home/puneet/puneet/office/alkimia/payment/backend/keyusermanagertest.cpp: In member function ‘void KeyUserManagerTest::settersAndGetters()’: /home/puneet/puneet/office/alkimia/payment/backend/keyusermanagertest.cpp:52: error: no matching function for call to ‘StorageUserManager::StorageUserManager()’ /home/puneet/puneet/office/alkimia/payment/backend/storageusermanager.h:41: note: candidates are: StorageUserManager::StorageUserManager(QObject*) /home/puneet/puneet/office/alkimia/payment/backend/storageusermanager.h:37: note: StorageUserManager::StorageUserManager(const StorageUserManager&) /home/puneet/puneet/office/alkimia/payment/backend/keyusermanagertest.cpp:53: error: no matching function for call to ‘KeyUserManager::KeyUserManager(StorageUserManager*&)’ /home/puneet/puneet/office/alkimia/payment/backend/keyusermanager.h:44: note: candidates are: KeyUserManager::KeyUserManager(StorageUserManager*, QObject*) /home/puneet/puneet/office/alkimia/payment/backend/keyusermanager.h:41: note: KeyUserManager::KeyUserManager(const KeyUserManager&)

Thanks

¿Fue útil?

Solución

Add constructor to your KeyUserManagerTest - in header add

KeyUserManagerTest (QObject* parent=0);

and in cpp

KeyUserManagerTest::KeyUserManagerTest(QObject* parent):QObject(parent){};

QOBJECT macro does not create constructor for you!

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top