PDA

View Full Version : error with QList with a class



john_god
11th January 2009, 10:43
:confused:
I have a QList with a class, and have this error:


C:/Qt4Examples/Matematica/calculadora.cpp:14: error: insufficient contextual information to determine type

My class is:



class ComplexData
{

public:
ComplexData();
ComplexData(const ComplexData &);
virtual ~ComplexData();

ComplexData &operator=(const ComplexData & ); // Right side is the argument.

QString StrFuncao;
double real;
double imag;
..............

void SetNumero(double);
//void SetNumero(Complexo);
void SetNumero(double, double);
void SetNumeroVar(double);
.................

};

My list, defined inside another class:



......
private:
QList<ComplexData> Pilha();
.......


I get the errors with basic QList functions:


ComplexData xx;

Pilha.append(xx);
.......
Pilha.clear();

Any ideas to solve this errors ?????

Thanks

rexi
11th January 2009, 12:03
......
private:
QList<ComplexData> Pilha();
.......



That's a method declaration, not a member variable.

john_god
11th January 2009, 13:39
I tried like this:



QList<ComplexData> Pilha;

but i've got the error:


C:/Qt4Examples/Matematica/calculadora.h:67: error: field `Pilha' has incomplete type

and

Pilha.clear(); //this code is inside a function of the class where Pilha was declared
gives the error:


C:/Qt4Examples/Matematica/calculadora.cpp:37: error: `Pilha' was not declared in this scope

rexi
11th January 2009, 14:51
Please post the complete code of the class in question. From these little fragments it's hard to see where the problem might be.

john_god
11th January 2009, 19:19
here is the header



#include <QString>

#include "complexo.h"

class ComplexData
{

public:
ComplexData();
ComplexData(const ComplexData &);
virtual ~ComplexData();

ComplexData &operator=(const ComplexData & ); // Right side is the argument.

QString StrFuncao;
double real;
double imag;
bool FlagNumero;
bool FlagDerivada;
int NivelParentesis;

void SetNumero(double);
//void SetNumero(Complexo);
void SetNumero(double, double);
void SetNumeroVar(double);
void SetFuncao(QString);
bool ValidaFuncao();
bool ValidaNumero();
bool ValidaOperadores();
bool ValidaFuncaoOperador();
bool ValidaParentesis();
bool ValidaConstantes();
bool ValidaConstantesFile(/*QString &*/);
bool ValidaImaginario();
int ValidaOperadorPrioridade();


};




the complexdata.cpp :





#include "complexdata.h"



ComplexData::ComplexData()
{
real=0;
imag=0;
StrFuncao="";
FlagNumero=true;
FlagDerivada=false;
NivelParentesis=0;
}

ComplexData::~ComplexData()
{

}


ComplexData &ComplexData::operator=(const ComplexData &dat )
{
FlagNumero=dat.FlagNumero;
FlagDerivada=dat.FlagDerivada;
real=dat.real;
imag=dat.imag;
StrFuncao=dat.StrFuncao;

return *this; // Assignment operator returns left side.
}

ComplexData::ComplexData(const ComplexData &dat)
{
FlagNumero=dat.FlagNumero;
FlagDerivada=dat.FlagDerivada;
real=dat.real;
imag=dat.imag;
StrFuncao=dat.StrFuncao;
// return *this; // Assignment operator returns left side.
}

void ComplexData::SetNumeroVar(double Numero)
{
real=Numero;
imag=0;
FlagNumero=true;
FlagDerivada=true;
StrFuncao.arg(Numero);
}


void ComplexData::SetNumero(double Numero)
{
real=Numero;
imag=0;
FlagNumero=true;
FlagDerivada=false;
StrFuncao.arg(Numero);
}

//void ComplexData::SetNumero(Complexo Numero)
void ComplexData::SetNumero(double r, double i)
{
//real=Numero.r;
//imag=Numero.i;
real=r;
imag=i;
FlagNumero=true;
FlagDerivada=false;

if (real == 0)
{
if (imag == 0)
StrFuncao.arg(real);

if (imag > 0)
StrFuncao.arg(imag);

if (imag < 0)
StrFuncao.arg(-imag);
}

if (real > 0)
{
if (imag == 0)
StrFuncao.arg(real);

if (imag > 0)
StrFuncao.arg(real+imag);

if (imag < 0)
StrFuncao.arg(real-imag);
}

if (real < 0)
{
if (imag == 0)
StrFuncao.arg(-real);

if (imag > 0)
StrFuncao.arg(-real+imag);

if (imag < 0)
StrFuncao.arg(-real-imag);
}



}


void ComplexData::SetFuncao(QString funcao)
{
real=0;
imag=0;
FlagNumero=false;
FlagDerivada=false;
StrFuncao=funcao;
}


bool ComplexData::ValidaNumero()
{
if (FlagNumero)
return 1;
else
return 0;
}


bool ComplexData::ValidaFuncao()
{

// int x = QString::compare("aUtO", "AuTo", Qt::CaseInsensitive); // x == 0

if (!StrFuncao.compare("sinc",Qt::CaseInsensitive))
return 1;

if (!StrFuncao.compare("sin",Qt::CaseInsensitive))
return 1;

if (!StrFuncao.compare("cos",Qt::CaseInsensitive))
return 1;

if (!StrFuncao.compare("tan",Qt::CaseInsensitive))
return 1;

if (!StrFuncao.compare("cotg",Qt::CaseInsensitive))
return 1;



if (!StrFuncao.compare("sinh",Qt::CaseInsensitive))
return 1;

if (!StrFuncao.compare("cosh",Qt::CaseInsensitive))
return 1;

if (!StrFuncao.compare("tanh",Qt::CaseInsensitive))
return 1;

if (!StrFuncao.compare("cotgh",Qt::CaseInsensitive))
return 1;



if (!StrFuncao.compare("asin",Qt::CaseInsensitive))
return 1;

if (!StrFuncao.compare("acos",Qt::CaseInsensitive))
return 1;

if (!StrFuncao.compare("atan",Qt::CaseInsensitive))
return 1;

if (!StrFuncao.compare("acotg",Qt::CaseInsensitive))
return 1;



if (!StrFuncao.compare("asinh",Qt::CaseInsensitive))
return 1;

if (!StrFuncao.compare("acosh",Qt::CaseInsensitive))
return 1;

if (!StrFuncao.compare("atanh",Qt::CaseInsensitive))
return 1;

if (!StrFuncao.compare("acotgh",Qt::CaseInsensitive))
return 1;



if (!StrFuncao.compare("sqrt",Qt::CaseInsensitive))
return 1;

if (!StrFuncao.compare("log",Qt::CaseInsensitive))
return 1;

if (!StrFuncao.compare("ln",Qt::CaseInsensitive))
return 1;

if (!StrFuncao.compare("exp",Qt::CaseInsensitive))
return 1;


return 0;
}




bool ComplexData::ValidaOperadores()
{

if (StrFuncao == "+")
return 1;

if (StrFuncao == "-")
return 1;

if (StrFuncao == "*")
return 1;

if (StrFuncao == "/")
return 1;

if (StrFuncao == "^")
return 1;

if (StrFuncao == "E")
return 1;


return 0;
}


bool ComplexData::ValidaParentesis()
{

if (StrFuncao == "(")
return 1;


if (StrFuncao == ")")
return 1;

if (StrFuncao == "|")
return 1;


return 0;
}


int ComplexData::ValidaOperadorPrioridade()
{
if (StrFuncao == "+" || StrFuncao == "-" )
return 0;

if (StrFuncao == "*" || StrFuncao == "/" )
return 1;

if (StrFuncao == "^" || StrFuncao == "E" )
return 2;

return -1;
}




bool ComplexData::ValidaFuncaoOperador()
{

if (ValidaFuncao())
return 1;

if (ValidaOperadores())
return 1;

if (ValidaParentesis())
return 1;

return 0;
}


bool ComplexData::ValidaConstantes()
{

if (FlagNumero && !StrFuncao.compare("pi",Qt::CaseInsensitive))
return 1;

if (FlagNumero && !StrFuncao.compare("e",Qt::CaseInsensitive))
return 1;

if (FlagNumero && !StrFuncao.compare("i",Qt::CaseInsensitive))
return 1;

if (FlagNumero && !StrFuncao.compare("j",Qt::CaseInsensitive))
return 1;

return 0;

}



bool ComplexData::ValidaConstantesFile(/*CString &valor*/)
{

FILE *fp_constantes;
QString aux_const;
// int i;


//Ficheiro de Constantes
if ( fp_constantes = fopen("constantes_file.dat","r") ) //abriu o ficheiro
{
// i=1;
while( fscanf(fp_constantes,"%s",aux_const) != EOF)
{

if (aux_const==StrFuncao)
{
// fscanf(fp_constantes,"%s",valor);

fclose (fp_constantes);
return true;
}

//i++;
}

fclose (fp_constantes);
}
/*else
{
AfxMessageBox("Erro ao abrir o ficheiro das Constantes");

}*/


return false;

}


bool ComplexData::ValidaImaginario()
{
if (FlagNumero && imag != 0)
return 1;


return 0;
}

wysota
11th January 2009, 19:46
#include <QList> is probably missing.

rexi
11th January 2009, 20:08
Well, the ComplexData class's code looks ok. But as I understand your question, and the excerpt of your code, it's the class where you use ComplexData that causes problems? So that's the code that would be of interest here...

So, please give us the code that causes that problem. I figure that would be calculadora.h/cpp.

john_god
12th January 2009, 21:48
I already find the error. Wysota has right, include QList was missing.
Thank guys, this was a basic error. : )