hi

i am following "The Book Of Qt 4 The art of Building Qt Applications" and trying the following example which converts byte to decimal, hexadecimal and binary but when i run, it produces error

here is the code
byteconverterdialog.h file
Qt Code:
  1. #ifndef BYTECONVERTERDIALOG_H
  2. #define BYTECONVERTERDIALOG_H
  3.  
  4. #include <QDialog>
  5.  
  6. class byteConverterDialog : public QDialog
  7. {
  8. Q_OBJECT
  9.  
  10. public:
  11. byteConverterDialog();
  12. };
  13.  
  14. #endif // BYTECONVERTERDIALOG_H
To copy to clipboard, switch view to plain text mode 

byteconverter.h
Qt Code:
  1. #ifndef BYTECONVERTER_H
  2. #define BYTECONVERTER_H
  3.  
  4. #include <QObject>
  5.  
  6. class ByteConverter : public QObject
  7. {
  8. Q_OBJECT
  9.  
  10. public:
  11. ByteConverter(QObject* = 0);
  12.  
  13. public slots:
  14. void setDec(const QString &);
  15. void setHex(const QString &);
  16. void setBin(const QString &);
  17.  
  18. signals:
  19. void decChanged(const QString&);
  20. void hexChanged(const QString&);
  21. void binChanged(const QString&);
  22. };
  23.  
  24. #endif // BYTECONVERTER_H
To copy to clipboard, switch view to plain text mode 

byteconverterdialog.cpp
Qt Code:
  1. #include "byteconverterdialog.h"
  2. #include "byteconverter.h"
  3. #include <QLabel>
  4. #include <QLineEdit>
  5. #include <QPushButton>
  6. #include <QVBoxLayout>
  7. #include <QHBoxLayout>
  8. #include <QGridLayout>
  9. #include <QIntValidator>
  10.  
  11. byteConverterDialog::byteConverterDialog()
  12. {
  13. //generate the necessary layouts
  14. QVBoxLayout *mainLayout = new QVBoxLayout(this);
  15. QGridLayout *editLayout = new QGridLayout;
  16. QHBoxLayout *buttonLayout = new QHBoxLayout;
  17.  
  18. mainLayout->addLayout(editLayout);
  19. mainLayout->addStretch();
  20. mainLayout->addLayout(buttonLayout);
  21.  
  22. //generate the labels and line-edits and add them to the object pointed at by editLayout
  23. QLabel *decLabel = new QLabel(tr("Decimal"));
  24. QLabel *hexLabel = new QLabel(tr("hexadecimal"));
  25. QLabel *binLabel = new QLabel(tr("Binary"));
  26.  
  27. decEdit = new QLineEdit;
  28. hexEdit = new QLineEdit;
  29. binEdit = new QLineEdit;
  30.  
  31. editLayout->addWidget(decLabel, 0, 0);
  32. editLayout->addWidget(decEdit, 0, 1);
  33. editLayout->addWidget(hexLabel, 1, 0);
  34. editLayout->addWidget(hexEdit, 1, 1);
  35. editLayout->addWidget(binLabel, 2, 0);
  36. editLayout->addWidget(binEdit, 2, 1);
  37.  
  38. //create the quit button and add it to the object pointed at by buttonLayout.
  39. QPushButton *exitButton = new QPushButton(tr("Quit"));
  40.  
  41. buttonLayout->addStretch();
  42. buttonLayout->addWidget(exitButton);
  43. exitButton->setDefault(true);
  44.  
  45. QIntValidator* decValidator =
  46. new QIntValidator(0, 255, decEdit);
  47. decEdit->setValidator(decValidator);
  48. QRegExpValidator* hexValidator =
  49. new QRegExpValidator(QRegExp("[0-9A-Fa-f]{1,2}"), hexEdit);
  50. hexEdit->setValidator(hexValidator);
  51. QRegExpValidator* binValidator =
  52. new QRegExpValidator(QRegExp("[01]{1,8}"), binEdit);
  53. binEdit->setValidator(binValidator);
  54.  
  55. setWindowTitle(tr("Byte Converter"));
  56.  
  57. connect(exitButton, SIGNAL(clicked()), this, SLOT(accept()));
  58.  
  59. ByteConverter* bc = new ByteConverter(this);
  60.  
  61. connect(decEdit, SIGNAL(textChanged(const QString &)), bc, SLOT(setDec(const QString &)));
  62. connect(hexEdit, SIGNAL(textChanged(const QString &)), bc, SLOT(setHex(const QString &)));
  63. connect(binEdit, SIGNAL(textChanged(const QString &)), bc, SLOT(setBin(const QString &)));
  64.  
  65. connect(bc, SIGNAL(decChanged(const QString&)), decEdit, SLOT(setText(const QString&)));
  66. connect(bc, SIGNAL(hexChanged(const QString&)), hexEdit, SLOT(setText(const QString&)));
  67. connect(bc, SIGNAL(binChanged(const QString&)), binEdit, SLOT(setText(const QString&)));
  68. }
  69.  
  70. void byteConverterDialog::decChanged(const QString& newValue)
  71. {
  72. bool ok;
  73. int num = newValue.toInt(&ok);
  74. if(ok) {
  75. hexEdit->setText(QString::number(num, 16));
  76. binEdit->setText(QString::number(num, 2));
  77. }
  78. else {
  79. hexEdit->setText("");
  80. binEdit->setText("");
  81. }
  82. }
  83.  
  84. void byteConverterDialog::hexChanged(const QString& newValue)
  85. {
  86. bool ok;
  87. int num = newValue.toInt(&ok);
  88. if(ok) {
  89. decEdit->setText(QString::number(num));
  90. binEdit->setText(QString::number(num, 2));
  91. }
  92. else {
  93. decEdit->setText("");
  94. binEdit->setText("");
  95. }
  96. }
  97.  
  98. void byteConverterDialog::binChanged(const QString& newValue)
  99. {
  100. bool ok;
  101. int num = newValue.toInt(&ok);
  102. if(ok) {
  103. decEdit->setText(QString::number(num));
  104. hexEdit->setText(QString::number(num, 16));
  105. }
  106. else {
  107. hexEdit->setText("");
  108. decEdit->setText("");
  109. }
  110. }
To copy to clipboard, switch view to plain text mode 

byteconverter.cpp
Qt Code:
  1. #include "byteconverter.h"
  2.  
  3. ByteConverter::ByteConverter(QObject* parent) : QObject(parent)
  4. {
  5. }
  6.  
  7. void ByteConverter::setDec(const QString& newValue)
  8. {
  9. bool ok;
  10. int num = newValue.toInt(&ok);
  11. if(ok) {
  12. emit hexChanged(QString::number(num, 16));
  13. emit binChanged(QString::number(num, 2));
  14. }
  15. else {
  16. emit hexChanged("");
  17. emit binChanged("");
  18. }
  19. }
  20.  
  21. void ByteConverter::setHex(const QString& newValue)
  22. {
  23. bool ok;
  24. int num = newValue.toInt(&ok, 16);
  25. if(ok) {
  26. emit decChanged(QString::number(num));
  27. emit binChanged(QString::number(num, 2));
  28. }
  29. else {
  30. emit decChanged("");
  31. emit binChanged("");
  32. }
  33. }
  34.  
  35. void ByteConverter::setBin(const QString& newValue)
  36. {
  37. bool ok;
  38. int num = newValue.toInt(&ok, 2);
  39. if(ok) {
  40. emit decChanged(QString::number(num));
  41. emit hexChanged(QString::number(num, 16));
  42. }
  43. else {
  44. emit decChanged("");
  45. emit hexChanged("");
  46. }
  47. }
To copy to clipboard, switch view to plain text mode 

main.cpp
Qt Code:
  1. #include <QtGui/QApplication>
  2. #include "byteconverterdialog.h"
  3.  
  4. int main(int argc, char *argv[])
  5. {
  6. QApplication a(argc, argv);
  7. byteConverterDialog bc;
  8. bc.setAttribute(Qt::WA_QuitOnClose);
  9. bc.show();
  10.  
  11. return a.exec();
  12. }
To copy to clipboard, switch view to plain text mode 

when i run this code, it displays these errors

Qt Code:
  1. decEdit was not declared in this scope byteconverterdialog.cpp 27
  2. hexEdit was not declared in this scope byteconverterdialog.cpp 28
  3. binEdit was not declared in this scope byteconverterdialog.cpp 29
  4.  
  5. void byteConverterDialog::decChanged(const QString&) member function declared in class byteConverterDialog byteconverterdialog.cpp 70
  6. void byteConverterDialog::hexChanged(const QString&) member function declared in class byteConverterDialog byteconverterdialog.cpp 84
  7. void byteConverterDialog::binChanged(const QString&) member function declared in class byteConverterDialog byteconverterdialog.cpp 98
To copy to clipboard, switch view to plain text mode