0

When i call the below function I gets the qmap empty. I read if my custom class is not derived from QObject and has copy constructor and assignment operator, it should work.

QMap<qint32, QMap<qint32, PayInOut> > mPayInOuts;


QMap<qint32, PayInOut> DataManager::getPayInModes()
{
    qDebug() << Q_FUNC_INFO << "Invoked";
    QMap<qint32, PayInOut> payInModes;

    if (mPayInOuts.contains(0))
    {
        qDebug() << Q_FUNC_INFO << "exists";
        payInModes = mPayInOuts.value(0);
    }

    qDebug() << Q_FUNC_INFO << "Exits" << payInModes.count();
    return payInModes;
}

I have a custom class, and it has copy constructor and assignment operator.

class PayInOut
{
public:
    PayInOut():code(0) {}
    PayInOut(const PayInOut &inOut):code(inOut.code), desc(inOut.desc),
                                    imagePixmap(inOut.imagePixmap) { }
    qint32 code;
    QString desc;
    QPixmap imagePixmap;

    PayInOut& operator= (const PayInOut &other)
    {
        if (this != &other)
        {
            this->code = other.code;
            this->desc = other.desc;
            this->imagePixmap = other.imagePixmap;
        }

        return *this;
    }
};
Martin G
  • 17,357
  • 9
  • 82
  • 98
A.J
  • 725
  • 10
  • 33

0 Answers0