Hi,

Why I see: Object::connect: No such slot QDialog::showName(QString) in ../DialogByButton/mainwindow.cpp:29

DialogByButton.pro
Qt Code:
  1. SOURCES += \
  2. main.cpp \
  3. mainwindow.cpp \
  4. dialog.cpp
  5.  
  6. HEADERS += \
  7. mainwindow.h \
  8. dialog.h
To copy to clipboard, switch view to plain text mode 

dialog.h
Qt Code:
  1. #ifndef DIALOG_H
  2. #define DIALOG_H
  3.  
  4. #include <QDialog>
  5. #include <QtGui>
  6.  
  7. class Dialog : public QDialog
  8. {
  9. Q_OBJECT
  10. public:
  11. explicit Dialog(QWidget *parent = 0);
  12.  
  13. signals:
  14.  
  15. public slots:
  16. void showName(QString name);
  17.  
  18. private:
  19. QLabel *lblName;
  20. };
  21.  
  22. #endif // DIALOG_H
To copy to clipboard, switch view to plain text mode 

dialog.cpp
Qt Code:
  1. #include "dialog.h"
  2.  
  3. Dialog::Dialog(QWidget *parent) :
  4. QDialog(parent)
  5. {
  6. // Controls
  7. lblName = new QLabel(tr("Hahah"));
  8.  
  9. // Layouts
  10. QHBoxLayout* mainLayout = new QHBoxLayout(this);
  11. mainLayout->addWidget(lblName);
  12.  
  13. // Set Layout
  14. this->setLayout(mainLayout);
  15. }
  16.  
  17. void Dialog::showName(QString name) {
  18. //lblName->setText(name);
  19. }
To copy to clipboard, switch view to plain text mode 

mainwindow.h
Qt Code:
  1. #ifndef MAINWINDOW_H
  2. #define MAINWINDOW_H
  3.  
  4. #include <QMainWindow>
  5. #include <QtGui>
  6.  
  7. class MainWindow : public QMainWindow
  8. {
  9. Q_OBJECT
  10. public:
  11. explicit MainWindow(QWidget *parent = 0);
  12.  
  13. signals:
  14. void sendName(QString name);
  15.  
  16. private slots:
  17. void callDialog();
  18.  
  19. private:
  20. QLineEdit *leName;
  21. };
  22.  
  23. #endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode 

mainwindow.cpp
Qt Code:
  1. #include "mainwindow.h"
  2. #include "dialog.h"
  3. #include <QWidget>
  4.  
  5. MainWindow::MainWindow(QWidget *parent) :
  6. QMainWindow(parent)
  7. {
  8. // Controls
  9. QLabel *lblName = new QLabel(tr("Enter your name:"));
  10. leName = new QLineEdit;
  11. QPushButton *btnCallDialog = new QPushButton(tr("Call Dialog"));
  12.  
  13. // Layout
  14. QGridLayout *mainLayout = new QGridLayout;
  15. mainLayout->addWidget(lblName, 0, 0);
  16. mainLayout->addWidget(leName, 0, 1);
  17. mainLayout->addWidget(btnCallDialog, 1, 0, 1, 2);
  18.  
  19. // Set center widget
  20. QWidget *widget = new QWidget;
  21. widget->setLayout(mainLayout);
  22. this->setCentralWidget(widget);
  23.  
  24. connect(btnCallDialog, SIGNAL(clicked()), this, SLOT(callDialog()));
  25. }
  26.  
  27. void MainWindow::callDialog() {
  28. QDialog *dialog = new QDialog(this);
  29. connect(this, SIGNAL(sendName(QString)), dialog, SLOT(showName(QString)));
  30. emit sendName(leName->text());
  31. dialog->show();
  32. }
To copy to clipboard, switch view to plain text mode 

main.cpp
Qt Code:
  1. #include <QApplication>
  2. #include "mainwindow.h"
  3.  
  4. int main (int argc, char *argv[]) {
  5. QApplication app(argc, argv);
  6.  
  7. MainWindow window;
  8. window.show();
  9.  
  10. return app.exec();
  11. }
To copy to clipboard, switch view to plain text mode 

Thank you!