I'm sure this is just a simple problem that I cannot find the answer to, but it is driving me crazy. I am declaring the QString variables oldName and oldAddress in my constructor function, but then when I try to use them in a function that I have in a slot, then I get the error "oldName was not declared in this scope"

Here is the relavent snippet of my code.

Qt Code:
  1. MainWindow::MainWindow(QWidget *parent) :
  2. QMainWindow(parent),
  3. ui(new Ui::MainWindow)
  4. {
  5. ui->setupUi(this);
  6. ui->pushButton_2->hide();
  7. ui->pushButton_3->hide();
  8. ui->lineEdit->setReadOnly(true);
  9. ui->textEdit->setReadOnly(true);
  10. QString oldName;
  11. QString oldAddress;
  12. }
  13.  
  14. MainWindow::~MainWindow()
  15. {
  16. delete ui;
  17. }
  18.  
  19. void MainWindow::add()
  20. {
  21. ui->pushButton_2->show();
  22. ui->pushButton_3->show();
  23. ui->pushButton->setEnabled(false);
  24. ui->lineEdit->setReadOnly(false);
  25. ui->textEdit->setReadOnly(false);
  26.  
  27. oldName = ui->lineEdit->text();
  28. oldAddress = ui->textEdit->toPlainText();
  29. }
To copy to clipboard, switch view to plain text mode 

Thank you for your help in advance