What does your func() function? As said in the last answer you have to call exec, in your case
Qt Code:
  1. void MainWindow::on_pushButton_clicked()
  2. {
  3. Dname = new name();
  4. name1->func(); // ? that won't compile...
  5. Dname->exec(); // <- new
  6. ui->label->setText(Dname->getCname()); // Here I am getting the problem (returning null string)
  7. }
To copy to clipboard, switch view to plain text mode 
or call show, but then you have to emit a signal from your dialog and fetch it in a slot of your main window where you then read the value of your line edit.