E
E
Evgeny Ivanovich2015-08-20 00:41:19
Qt
Evgeny Ivanovich, 2015-08-20 00:41:19

Why is the class member missing?

In general, the thing is, there is a class

#ifndef QMAPVALIDATOR_H
#define QMAPVALIDATOR_H

#include <QObject>
#include <QStringList>
#include <QVariantMap>

class QMapValidator
{
private:
    QStringList params;
    QVariantMap *valider;

public:
    QMapValidator();
    QMapValidator( QStringList initial, QVariantMap *valider );
    bool isValid();

protected:
    bool addValid( const QString &param );
};

#endif // QMAPVALIDATOR_H

#include "qmapvalidator.h"

QMapValidator::QMapValidator()
{
}

QMapValidator::QMapValidator(QStringList initial, QVariantMap *valider)
{
    params = initial;

    this->valider = valider;

}

bool QMapValidator::isValid()
{
    qDebug() << params ; //Тут объекта уже не существует. ???

    if( params.isEmpty() )
    {
        qDebug() << "List is empty"; //Соответственно видим это..
        return false;
    }

    foreach( QString param, params )
    {
       qDebug() << param;
        if( ! valider->contains( param ) )
            return false;
    }

    return true;
}

bool QMapValidator::addValid(const QString &param)
{
    if( ! params.contains( param ) )
    {
        params.append( param ); //Тут все верно. И если после этого вывести param то видим что лист сохраняет строки.
        return true;
    }

    return false;
}

In general, the essence is this. I inherit public from this class, in the constructor I specify the list of necessary map parameters and a pointer to the map itself. I optionally add elements with addValid( const QString ¶m ).
When calling isValid() in the body of the method, the presence of parameters in the map should be checked, and if any parameter is missing, then we throw out FALSE. BUT! In the body of the method, the list of params strings does not exist! I tried to allocate memory on the heap during initialization - duck generally says they say an empty pointer .. Who knows what kind of garbage?
Version Qt Creator 3.4.2 (opensource)
Based on Qt 5.5.0 (MSVC 2013, 32 bits)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
tsarevfs, 2015-08-20
@Pauk_Code

Show how you create your class, how you call isValid() and the constructor of your class. Are you not deleting an instance of your class at some point? Well, I advise you to go through the debugger.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question