Hi,
Why I see: Object::connect: No such slot QDialog::showName(QString) in ../DialogByButton/mainwindow.cpp:29
DialogByButton.pro
SOURCES += \
main.cpp \
mainwindow.cpp \
dialog.cpp
HEADERS += \
mainwindow.h \
dialog.h
SOURCES += \
main.cpp \
mainwindow.cpp \
dialog.cpp
HEADERS += \
mainwindow.h \
dialog.h
To copy to clipboard, switch view to plain text mode
dialog.h
#ifndef DIALOG_H
#define DIALOG_H
#include <QDialog>
#include <QtGui>
{
Q_OBJECT
public:
explicit Dialog
(QWidget *parent
= 0);
signals:
public slots:
private:
};
#endif // DIALOG_H
#ifndef DIALOG_H
#define DIALOG_H
#include <QDialog>
#include <QtGui>
class Dialog : public QDialog
{
Q_OBJECT
public:
explicit Dialog(QWidget *parent = 0);
signals:
public slots:
void showName(QString name);
private:
QLabel *lblName;
};
#endif // DIALOG_H
To copy to clipboard, switch view to plain text mode
dialog.cpp
#include "dialog.h"
{
// Controls
lblName
= new QLabel(tr
("Hahah"));
// Layouts
mainLayout->addWidget(lblName);
// Set Layout
this->setLayout(mainLayout);
}
void Dialog
::showName(QString name
) { //lblName->setText(name);
}
#include "dialog.h"
Dialog::Dialog(QWidget *parent) :
QDialog(parent)
{
// Controls
lblName = new QLabel(tr("Hahah"));
// Layouts
QHBoxLayout* mainLayout = new QHBoxLayout(this);
mainLayout->addWidget(lblName);
// Set Layout
this->setLayout(mainLayout);
}
void Dialog::showName(QString name) {
//lblName->setText(name);
}
To copy to clipboard, switch view to plain text mode
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QtGui>
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
signals:
private slots:
void callDialog();
private:
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QtGui>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
signals:
void sendName(QString name);
private slots:
void callDialog();
private:
QLineEdit *leName;
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
mainwindow.cpp
#include "mainwindow.h"
#include "dialog.h"
#include <QWidget>
MainWindow
::MainWindow(QWidget *parent
) :{
// Controls
// Layout
mainLayout->addWidget(lblName, 0, 0);
mainLayout->addWidget(leName, 0, 1);
mainLayout->addWidget(btnCallDialog, 1, 0, 1, 2);
// Set center widget
widget->setLayout(mainLayout);
this->setCentralWidget(widget);
connect(btnCallDialog, SIGNAL(clicked()), this, SLOT(callDialog()));
}
void MainWindow::callDialog() {
connect(this,
SIGNAL(sendName
(QString)), dialog,
SLOT(showName
(QString)));
emit sendName(leName->text());
dialog->show();
}
#include "mainwindow.h"
#include "dialog.h"
#include <QWidget>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)
{
// Controls
QLabel *lblName = new QLabel(tr("Enter your name:"));
leName = new QLineEdit;
QPushButton *btnCallDialog = new QPushButton(tr("Call Dialog"));
// Layout
QGridLayout *mainLayout = new QGridLayout;
mainLayout->addWidget(lblName, 0, 0);
mainLayout->addWidget(leName, 0, 1);
mainLayout->addWidget(btnCallDialog, 1, 0, 1, 2);
// Set center widget
QWidget *widget = new QWidget;
widget->setLayout(mainLayout);
this->setCentralWidget(widget);
connect(btnCallDialog, SIGNAL(clicked()), this, SLOT(callDialog()));
}
void MainWindow::callDialog() {
QDialog *dialog = new QDialog(this);
connect(this, SIGNAL(sendName(QString)), dialog, SLOT(showName(QString)));
emit sendName(leName->text());
dialog->show();
}
To copy to clipboard, switch view to plain text mode
main.cpp
#include <QApplication>
#include "mainwindow.h"
int main (int argc, char *argv[]) {
MainWindow window;
window.show();
return app.exec();
}
#include <QApplication>
#include "mainwindow.h"
int main (int argc, char *argv[]) {
QApplication app(argc, argv);
MainWindow window;
window.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Thank you!
Bookmarks