Results 1 to 8 of 8

Thread: error with QList with a class

  1. #1
    Join Date
    Aug 2008
    Location
    Algarve, Portugal
    Posts
    288
    Thanks
    23
    Thanked 32 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Question error with QList with a class


    I have a QList with a class, and have this error:

    Qt Code:
    1. C:/Qt4Examples/Matematica/calculadora.cpp:14: error: insufficient contextual information to determine type
    To copy to clipboard, switch view to plain text mode 

    My class is:


    Qt Code:
    1. class ComplexData
    2. {
    3.  
    4. public:
    5. ComplexData();
    6. ComplexData(const ComplexData &);
    7. virtual ~ComplexData();
    8.  
    9. ComplexData &operator=(const ComplexData & ); // Right side is the argument.
    10.  
    11. QString StrFuncao;
    12. double real;
    13. double imag;
    14. ..............
    15.  
    16. void SetNumero(double);
    17. //void SetNumero(Complexo);
    18. void SetNumero(double, double);
    19. void SetNumeroVar(double);
    20. .................
    21.  
    22. };
    To copy to clipboard, switch view to plain text mode 

    My list, defined inside another class:

    Qt Code:
    1. ......
    2. private:
    3. QList<ComplexData> Pilha();
    4. .......
    To copy to clipboard, switch view to plain text mode 

    I get the errors with basic QList functions:

    Qt Code:
    1. ComplexData xx;
    2.  
    3. Pilha.append(xx);
    4. .......
    5. Pilha.clear();
    To copy to clipboard, switch view to plain text mode 

    Any ideas to solve this errors ?????

    Thanks

  2. #2
    Join Date
    Nov 2008
    Posts
    142
    Thanks
    3
    Thanked 20 Times in 20 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: error with QList with a class

    Quote Originally Posted by john_god View Post
    Qt Code:
    1. ......
    2. private:
    3. QList<ComplexData> Pilha();
    4. .......
    To copy to clipboard, switch view to plain text mode 
    That's a method declaration, not a member variable.

  3. #3
    Join Date
    Aug 2008
    Location
    Algarve, Portugal
    Posts
    288
    Thanks
    23
    Thanked 32 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: error with QList with a class

    I tried like this:


    Qt Code:
    1. QList<ComplexData> Pilha;
    To copy to clipboard, switch view to plain text mode 

    but i've got the error:

    Qt Code:
    1. C:/Qt4Examples/Matematica/calculadora.h:67: error: field `Pilha' has incomplete type
    To copy to clipboard, switch view to plain text mode 

    and
    Qt Code:
    1. Pilha.clear(); //this code is inside a function of the class where Pilha was declared
    To copy to clipboard, switch view to plain text mode 
    gives the error:

    Qt Code:
    1. C:/Qt4Examples/Matematica/calculadora.cpp:37: error: `Pilha' was not declared in this scope
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Nov 2008
    Posts
    142
    Thanks
    3
    Thanked 20 Times in 20 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: error with QList with a class

    Please post the complete code of the class in question. From these little fragments it's hard to see where the problem might be.

  5. #5
    Join Date
    Aug 2008
    Location
    Algarve, Portugal
    Posts
    288
    Thanks
    23
    Thanked 32 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: error with QList with a class

    here is the header


    Qt Code:
    1. #include <QString>
    2.  
    3. #include "complexo.h"
    4.  
    5. class ComplexData
    6. {
    7.  
    8. public:
    9. ComplexData();
    10. ComplexData(const ComplexData &);
    11. virtual ~ComplexData();
    12.  
    13. ComplexData &operator=(const ComplexData & ); // Right side is the argument.
    14.  
    15. QString StrFuncao;
    16. double real;
    17. double imag;
    18. bool FlagNumero;
    19. bool FlagDerivada;
    20. int NivelParentesis;
    21.  
    22. void SetNumero(double);
    23. //void SetNumero(Complexo);
    24. void SetNumero(double, double);
    25. void SetNumeroVar(double);
    26. void SetFuncao(QString);
    27. bool ValidaFuncao();
    28. bool ValidaNumero();
    29. bool ValidaOperadores();
    30. bool ValidaFuncaoOperador();
    31. bool ValidaParentesis();
    32. bool ValidaConstantes();
    33. bool ValidaConstantesFile(/*QString &*/);
    34. bool ValidaImaginario();
    35. int ValidaOperadorPrioridade();
    36.  
    37.  
    38. };
    To copy to clipboard, switch view to plain text mode 



    the complexdata.cpp :


    Qt Code:
    1. #include "complexdata.h"
    2.  
    3.  
    4.  
    5. ComplexData::ComplexData()
    6. {
    7. real=0;
    8. imag=0;
    9. StrFuncao="";
    10. FlagNumero=true;
    11. FlagDerivada=false;
    12. NivelParentesis=0;
    13. }
    14.  
    15. ComplexData::~ComplexData()
    16. {
    17.  
    18. }
    19.  
    20.  
    21. ComplexData &ComplexData::operator=(const ComplexData &dat )
    22. {
    23. FlagNumero=dat.FlagNumero;
    24. FlagDerivada=dat.FlagDerivada;
    25. real=dat.real;
    26. imag=dat.imag;
    27. StrFuncao=dat.StrFuncao;
    28.  
    29. return *this; // Assignment operator returns left side.
    30. }
    31.  
    32. ComplexData::ComplexData(const ComplexData &dat)
    33. {
    34. FlagNumero=dat.FlagNumero;
    35. FlagDerivada=dat.FlagDerivada;
    36. real=dat.real;
    37. imag=dat.imag;
    38. StrFuncao=dat.StrFuncao;
    39. // return *this; // Assignment operator returns left side.
    40. }
    41.  
    42. void ComplexData::SetNumeroVar(double Numero)
    43. {
    44. real=Numero;
    45. imag=0;
    46. FlagNumero=true;
    47. FlagDerivada=true;
    48. StrFuncao.arg(Numero);
    49. }
    50.  
    51.  
    52. void ComplexData::SetNumero(double Numero)
    53. {
    54. real=Numero;
    55. imag=0;
    56. FlagNumero=true;
    57. FlagDerivada=false;
    58. StrFuncao.arg(Numero);
    59. }
    60.  
    61. //void ComplexData::SetNumero(Complexo Numero)
    62. void ComplexData::SetNumero(double r, double i)
    63. {
    64. //real=Numero.r;
    65. //imag=Numero.i;
    66. real=r;
    67. imag=i;
    68. FlagNumero=true;
    69. FlagDerivada=false;
    70.  
    71. if (real == 0)
    72. {
    73. if (imag == 0)
    74. StrFuncao.arg(real);
    75.  
    76. if (imag > 0)
    77. StrFuncao.arg(imag);
    78.  
    79. if (imag < 0)
    80. StrFuncao.arg(-imag);
    81. }
    82.  
    83. if (real > 0)
    84. {
    85. if (imag == 0)
    86. StrFuncao.arg(real);
    87.  
    88. if (imag > 0)
    89. StrFuncao.arg(real+imag);
    90.  
    91. if (imag < 0)
    92. StrFuncao.arg(real-imag);
    93. }
    94.  
    95. if (real < 0)
    96. {
    97. if (imag == 0)
    98. StrFuncao.arg(-real);
    99.  
    100. if (imag > 0)
    101. StrFuncao.arg(-real+imag);
    102.  
    103. if (imag < 0)
    104. StrFuncao.arg(-real-imag);
    105. }
    106.  
    107.  
    108.  
    109. }
    110.  
    111.  
    112. void ComplexData::SetFuncao(QString funcao)
    113. {
    114. real=0;
    115. imag=0;
    116. FlagNumero=false;
    117. FlagDerivada=false;
    118. StrFuncao=funcao;
    119. }
    120.  
    121.  
    122. bool ComplexData::ValidaNumero()
    123. {
    124. if (FlagNumero)
    125. return 1;
    126. else
    127. return 0;
    128. }
    129.  
    130.  
    131. bool ComplexData::ValidaFuncao()
    132. {
    133.  
    134. // int x = QString::compare("aUtO", "AuTo", Qt::CaseInsensitive); // x == 0
    135.  
    136. if (!StrFuncao.compare("sinc",Qt::CaseInsensitive))
    137. return 1;
    138.  
    139. if (!StrFuncao.compare("sin",Qt::CaseInsensitive))
    140. return 1;
    141.  
    142. if (!StrFuncao.compare("cos",Qt::CaseInsensitive))
    143. return 1;
    144.  
    145. if (!StrFuncao.compare("tan",Qt::CaseInsensitive))
    146. return 1;
    147.  
    148. if (!StrFuncao.compare("cotg",Qt::CaseInsensitive))
    149. return 1;
    150.  
    151.  
    152.  
    153. if (!StrFuncao.compare("sinh",Qt::CaseInsensitive))
    154. return 1;
    155.  
    156. if (!StrFuncao.compare("cosh",Qt::CaseInsensitive))
    157. return 1;
    158.  
    159. if (!StrFuncao.compare("tanh",Qt::CaseInsensitive))
    160. return 1;
    161.  
    162. if (!StrFuncao.compare("cotgh",Qt::CaseInsensitive))
    163. return 1;
    164.  
    165.  
    166.  
    167. if (!StrFuncao.compare("asin",Qt::CaseInsensitive))
    168. return 1;
    169.  
    170. if (!StrFuncao.compare("acos",Qt::CaseInsensitive))
    171. return 1;
    172.  
    173. if (!StrFuncao.compare("atan",Qt::CaseInsensitive))
    174. return 1;
    175.  
    176. if (!StrFuncao.compare("acotg",Qt::CaseInsensitive))
    177. return 1;
    178.  
    179.  
    180.  
    181. if (!StrFuncao.compare("asinh",Qt::CaseInsensitive))
    182. return 1;
    183.  
    184. if (!StrFuncao.compare("acosh",Qt::CaseInsensitive))
    185. return 1;
    186.  
    187. if (!StrFuncao.compare("atanh",Qt::CaseInsensitive))
    188. return 1;
    189.  
    190. if (!StrFuncao.compare("acotgh",Qt::CaseInsensitive))
    191. return 1;
    192.  
    193.  
    194.  
    195. if (!StrFuncao.compare("sqrt",Qt::CaseInsensitive))
    196. return 1;
    197.  
    198. if (!StrFuncao.compare("log",Qt::CaseInsensitive))
    199. return 1;
    200.  
    201. if (!StrFuncao.compare("ln",Qt::CaseInsensitive))
    202. return 1;
    203.  
    204. if (!StrFuncao.compare("exp",Qt::CaseInsensitive))
    205. return 1;
    206.  
    207.  
    208. return 0;
    209. }
    210.  
    211.  
    212.  
    213.  
    214. bool ComplexData::ValidaOperadores()
    215. {
    216.  
    217. if (StrFuncao == "+")
    218. return 1;
    219.  
    220. if (StrFuncao == "-")
    221. return 1;
    222.  
    223. if (StrFuncao == "*")
    224. return 1;
    225.  
    226. if (StrFuncao == "/")
    227. return 1;
    228.  
    229. if (StrFuncao == "^")
    230. return 1;
    231.  
    232. if (StrFuncao == "E")
    233. return 1;
    234.  
    235.  
    236. return 0;
    237. }
    238.  
    239.  
    240. bool ComplexData::ValidaParentesis()
    241. {
    242.  
    243. if (StrFuncao == "(")
    244. return 1;
    245.  
    246.  
    247. if (StrFuncao == ")")
    248. return 1;
    249.  
    250. if (StrFuncao == "|")
    251. return 1;
    252.  
    253.  
    254. return 0;
    255. }
    256.  
    257.  
    258. int ComplexData::ValidaOperadorPrioridade()
    259. {
    260. if (StrFuncao == "+" || StrFuncao == "-" )
    261. return 0;
    262.  
    263. if (StrFuncao == "*" || StrFuncao == "/" )
    264. return 1;
    265.  
    266. if (StrFuncao == "^" || StrFuncao == "E" )
    267. return 2;
    268.  
    269. return -1;
    270. }
    271.  
    272.  
    273.  
    274.  
    275. bool ComplexData::ValidaFuncaoOperador()
    276. {
    277.  
    278. if (ValidaFuncao())
    279. return 1;
    280.  
    281. if (ValidaOperadores())
    282. return 1;
    283.  
    284. if (ValidaParentesis())
    285. return 1;
    286.  
    287. return 0;
    288. }
    289.  
    290.  
    291. bool ComplexData::ValidaConstantes()
    292. {
    293.  
    294. if (FlagNumero && !StrFuncao.compare("pi",Qt::CaseInsensitive))
    295. return 1;
    296.  
    297. if (FlagNumero && !StrFuncao.compare("e",Qt::CaseInsensitive))
    298. return 1;
    299.  
    300. if (FlagNumero && !StrFuncao.compare("i",Qt::CaseInsensitive))
    301. return 1;
    302.  
    303. if (FlagNumero && !StrFuncao.compare("j",Qt::CaseInsensitive))
    304. return 1;
    305.  
    306. return 0;
    307.  
    308. }
    309.  
    310.  
    311.  
    312. bool ComplexData::ValidaConstantesFile(/*CString &valor*/)
    313. {
    314.  
    315. FILE *fp_constantes;
    316. QString aux_const;
    317. // int i;
    318.  
    319.  
    320. //Ficheiro de Constantes
    321. if ( fp_constantes = fopen("constantes_file.dat","r") ) //abriu o ficheiro
    322. {
    323. // i=1;
    324. while( fscanf(fp_constantes,"%s",aux_const) != EOF)
    325. {
    326.  
    327. if (aux_const==StrFuncao)
    328. {
    329. // fscanf(fp_constantes,"%s",valor);
    330.  
    331. fclose (fp_constantes);
    332. return true;
    333. }
    334.  
    335. //i++;
    336. }
    337.  
    338. fclose (fp_constantes);
    339. }
    340. /*else
    341.   {
    342.   AfxMessageBox("Erro ao abrir o ficheiro das Constantes");
    343.  
    344.   }*/
    345.  
    346.  
    347. return false;
    348.  
    349. }
    350.  
    351.  
    352. bool ComplexData::ValidaImaginario()
    353. {
    354. if (FlagNumero && imag != 0)
    355. return 1;
    356.  
    357.  
    358. return 0;
    359. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: error with QList with a class

    #include <QList> is probably missing.

  7. The following user says thank you to wysota for this useful post:

    john_god (12th January 2009)

  8. #7
    Join Date
    Nov 2008
    Posts
    142
    Thanks
    3
    Thanked 20 Times in 20 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: error with QList with a class

    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.

  9. The following user says thank you to rexi for this useful post:

    john_god (12th January 2009)

  10. #8
    Join Date
    Aug 2008
    Location
    Algarve, Portugal
    Posts
    288
    Thanks
    23
    Thanked 32 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: error with QList with a class

    I already find the error. Wysota has right, include QList was missing.
    Thank guys, this was a basic error. : )

Similar Threads

  1. Replies: 3
    Last Post: 27th December 2008, 19:34
  2. class QHBoxLayout
    By csvivek in forum Installation and Deployment
    Replies: 2
    Last Post: 10th April 2008, 07:57
  3. How to use Signal through direct connection
    By santosh.kumar in forum Qt Programming
    Replies: 1
    Last Post: 14th December 2007, 07:07
  4. using Qlist with a class
    By Havard in forum Qt Programming
    Replies: 10
    Last Post: 24th February 2007, 19:38
  5. Replies: 2
    Last Post: 4th May 2006, 19:17

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.