error: 'display' was not declared in this scope

Hi
i developing a calculator by using kdeveloper and Qt and i have the following error when i compile my codes.what is wrong with my codes?

compiling calc.cpp (g++)
/home/roncriss/calc/src/calc.cpp: In constructor 'calc::calc(QWidget*, const char*, bool, uint)':
/home/roncriss/calc/src/calc.cpp:28: error: 'display' was not declared in this scope
/home/roncriss/calc/src/calc.cpp: In member function 'virtual void calc::sqrt()':
/home/roncriss/calc/src/calc.cpp:44: error: 'display' was not declared in this scope
/home/roncriss/calc/src/calc.cpp: In member function 'virtual void calc::clear()':
/home/roncriss/calc/src/calc.cpp:50: error: 'display' was not declared in this scope
/home/roncriss/calc/src/calc.cpp: In member function 'virtual void calc::dot()':
/home/roncriss/calc/src/calc.cpp:65: warning: comparison between signed and unsigned integer expressions
/home/roncriss/calc/src/calc.cpp:79: error: 'display' was not declared in this scope
/home/roncriss/calc/src/calc.cpp: In member function 'virtual void calc::equal()':
/home/roncriss/calc/src/calc.cpp:88: error: 'display' was not declared in this scope
/home/roncriss/calc/src/calc.cpp: In member function 'virtual void calc::mult()':
/home/roncriss/calc/src/calc.cpp:107: error: 'display' was not declared in this scope
/home/roncriss/calc/src/calc.cpp: In member function 'virtual void calc::div()':
/home/roncriss/calc/src/calc.cpp:125: error: 'display' was not declared in this scope
/home/roncriss/calc/src/calc.cpp: In member function 'virtual void calc::sub()':
/home/roncriss/calc/src/calc.cpp:143: error: 'display' was not declared in this scope
/home/roncriss/calc/src/calc.cpp: In member function 'virtual void calc::add()':
/home/roncriss/calc/src/calc.cpp:160: error: 'display' was not declared in this scope
/home/roncriss/calc/src/calc.cpp: In member function 'virtual void calc::zero()':
/home/roncriss/calc/src/calc.cpp:173: error: 'display' was not declared in this scope
/home/roncriss/calc/src/calc.cpp: In member function 'virtual void calc::one()':
/home/roncriss/calc/src/calc.cpp:181: error: 'display' was not declared in this scope
/home/roncriss/calc/src/calc.cpp: In member function 'virtual void calc::two()':
/home/roncriss/calc/src/calc.cpp:188: error: 'display' was not declared in this scope
/home/roncriss/calc/src/calc.cpp: In member function 'virtual void calc::three()':
/home/roncriss/calc/src/calc.cpp:196: error: 'display' was not declared in this scope
/home/roncriss/calc/src/calc.cpp: In member function 'virtual void calc::four()':
/home/roncriss/calc/src/calc.cpp:203: error: 'display' was not declared in this scope
/home/roncriss/calc/src/calc.cpp: In member function 'virtual void calc::five()':
/home/roncriss/calc/src/calc.cpp:210: error: 'display' was not declared in this scope
/home/roncriss/calc/src/calc.cpp: In member function 'virtual void calc::six()':
/home/roncriss/calc/src/calc.cpp:217: error: 'display' was not declared in this scope
/home/roncriss/calc/src/calc.cpp: In member function 'virtual void calc::seven()':
/home/roncriss/calc/src/calc.cpp:224: error: 'display' was not declared in this scope
/home/roncriss/calc/src/calc.cpp: In member function 'virtual void calc::eight()':
/home/roncriss/calc/src/calc.cpp:231: error: 'display' was not declared in this scope
/home/roncriss/calc/src/calc.cpp: In member function 'virtual void calc::nine()':
/home/roncriss/calc/src/calc.cpp:238: error: 'display' was not declared in this scope

Here are my codes
Calc.cpp

#include <stdlib.h>
#include <qlineedit.h>
#include "calc.h"
#include <string>

using namespace std;

#include <sstream>
#include "calculator.cpp"

Calc op;

string c;

// CONVERT FLOAT TO STRING
string f2s(double num)
{
ostringstream my_stream;
my_stream << num <<flush;
return my_stream.str();
}
calc::calc ( QWidget* parent, const char* name, bool modal, WFlags fl )
: Calculator ( parent,name, modal,fl )
{
display->setText("0");
c = "";
}
calc::~calc()
{
}
/*$SPECIALIZATION$*/
void calc::sqrt()
{
if( op.stack_spot == 0 )
op.Operation(c);

op.Operation("Sqrt");
c = "";
display->setText(f2s(op.Number));
}
/**************************************************************************/
/**************************************************************************/
void calc::clear()
{
display ->clear();
c = "";
display->insert("0");
//CLEAR IN OUR CLASS
op.Operation("Clear");
}
/**************************************************************************/
/**************************************************************************/
void calc::dot()
{
int error = 0;

/* Scan to see if a decimal already exist */
if( c.length() != 0)
{
for (int i = 0; i < c.length(); i++)
if(c.substr(i,1) == ".")
{
error = 1;
break;
}
}

if ( error == 0)
{
if ( c == "")
c = c + "0.";
else
c = c + ".";
display->setText(c);
}
}

void calc::equal()
{
if ( op.stack_spot == 2)
op.Operation(c);
c = "";
display -> setText( f2s(op.Number));
}
/**************************************************************************/
/**************************************************************************/
void calc::mult()
{
if((op.stack_spot == 0) || (op.stack_spot == 2))
{
op.Operation(c);
op.Operation("*");
}
else if(op.stack_spot == 1)
{
op.Operation("*");
}

c = "";
display->setText(f2s(op.Number));
}
/**************************************************************************/

void calc::div()
{
if((op.stack_spot == 0) || (op.stack_spot == 2))
{
op.Operation(c);
op.Operation("/");
}
else if(op.stack_spot == 1)
{
op.Operation("/");
}

c = "";
display->setText(f2s(op.Number));
}
/**************************************************************************/
void calc::sub()
{
if((op.stack_spot == 0) || (op.stack_spot == 2))
{
op.Operation(c);
op.Operation("-");
}
else if(op.stack_spot == 1)
{
op.Operation("-");
}

c = "";
display->setText(f2s(op.Number));
}
/**************************************************************************/
void calc::add()
{
if((op.stack_spot == 0) || (op.stack_spot == 2))
{
op.Operation(c);
op.Operation("+");
}
else if(op.stack_spot == 1)
{
op.Operation("+");
}

c = "";
display->setText(f2s(op.Number));
}
/**************************************************************************/

void calc::zero()
{
if ( c != "")
{
c = c + "0";
display->setText(c);
}
}
/**************************************************************************/
/**************************************************************************/
void calc::one()
{
c = c + "1";
display->setText(c);
}
/**************************************************************************/
void calc::two()
{
c = c + "2";
display->setText(c);

}
/**************************************************************************/
void calc::three()
{
c = c + "3";
display->setText(c);
}
/**************************************************************************/
void calc::four()
{
c = c + "4";
display->setText(c);
}
/**************************************************************************/
void calc::five()
{
c = c + "5";
display->setText(c);
}
/**************************************************************************/
void calc::six()
{
c = c + "6";
display->setText(c);

/**************************************************************************/
void calc::seven()
{
c = c + "7";
display->setText(c);
}
/**************************************************************************/
void calc::eight()
{
c = c + "8";
display->setText(c);
}
/**************************************************************************/
/**************************************************************************/
void calc::nine()
{
c = c + "9";
display->setText(c);
}
/**************************************************************************/
/**************************************************************************/
#include "calc.moc"

It means that each time you try to use that display variable the compiler has no idea what you are talking about.

Where and how is it defined?

BTW. Line 9. Unless KDevelop did this I would reconsider why you are #including a .cpp file..

You should also stop referring to op directly (as in op.Operation(...);). An object should generally only manipulate itself:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
void calc::clear()
  {
  // is 'display' some global variable somewhere?
  // is it a label in some other class object?
  display->setText("0");

  // don't play with global variables like this
  c = "";

  // choice one
  Operation("Clear");
  // choice two
  this->Operation("Clear");
  }

Watch your capitalization. Is it "Calc" or "calc"?

I'm also a little wary about those two globals, 'op' and 'c'.

You should take some time to read through the Qt docs and tutorials on Signals and Slots in order to hook two objects together.

Hope this helps.
Topic archived. No new replies allowed.