Connecting custom signal and slot
Hello!
I have a small problem with connecting the custom signal and the custom slot(Object::connect: No such signal)
Here is the code, what I have:
datedialog.h:
Code:
#ifndef DATEDIALOG_H
#define DATEDIALOG_H
#include <QDialog>
{
Q_OBJECT
public:
signals:
void SendText
(const QString &text
);
private:
void Initialization();
void PlacingElements();
private slots:
void EnableOKButton
(const QString &text
);
void GetDateToLine();
void BeforeShowMsg();
void ShowMessageBox
(const QString &text
);
private:
};
#endif // DATEDIALOG_H
datedialog.cpp
Code:
#include "datedialog.h"
#include <QHBoxLayout>
#include <QCalendarWidget>
#include <QLineEdit>
#include <QPushButton>
#include <QIcon>
#include <QString>
#include <QMessageBox>
{
Initialization();
}
void DateDialog::Initialization()
{
line->setFocus();
OkButton->setDefault(true);
OkButton->setEnabled(false);
connect(this->calendar, SIGNAL(selectionChanged()),
this, SLOT(GetDateToLine()));
connect(this
->line,
SIGNAL(textChanged
(const QString &)),
this,
SLOT(EnableOKButton
(const QString &)));
connect(this->OkButton, SIGNAL(clicked()),
this, SLOT(BeforeShowMsg()));
connect(this,
SIGNAL(SendText
(cosnt
QString &)),
this,
SLOT(ShowMessageBox
(const QString &)));
PlacingElements();
}
void DateDialog::PlacingElements()
{
leftTop->addWidget(this->line);
leftDown->addWidget(OkButton);
left->addLayout(leftTop);
left->addStretch();
left->addLayout(leftDown);
right->addWidget(this->calendar);
main->addLayout(left);
main->addLayout(right);
this->setLayout(main);
this
->setWindowTitle
(QObject::tr("Date"));
QString FilePath
= "E:\\linux-penguin-computing.jpg";
this
->setWindowIcon
(QIcon(FilePath
));
this->setFixedSize(sizeHint().width(), sizeHint().height());
}
void DateDialog
::EnableOKButton(const QString &text
) {
this->OkButton->setEnabled(!text.isEmpty());
OkButton->setEnabled(true);
}
void DateDialog::GetDateToLine()
{
this->line->setText(calendar->selectedDate().toString("dd/MM/yyyy dddd"));
}
void DateDialog
::ShowMessageBox(const QString &text
) {
msg.setText(text);
msg.
setWindowTitle(QObject::tr("Information before closing"));
msg.exec();
this->close();
}
void DateDialog::BeforeShowMsg()
{
if(!line->text().isEmpty())
{
emit SendText(line->text());
}
}
main.cpp:
Code:
#include <QtGui/QApplication>
#include "datedialog.h"
int main(int argc, char *argv[])
{
DateDialog date;
date.exec();
return app.exec();
}
The first question that I have is: why?
And the second one is: How it can be rectified?
Thank you beforehand for answers.
Re: Connecting custom signal and slot
You have a typo - "cosnt" in line 29.
Re: Connecting custom signal and slot
Thank you so much! I didn't notice that typo at all.
Re: Connecting custom signal and slot
You have to use QObject::connect method.
Re: Connecting custom signal and slot
Quote:
Originally Posted by
Gokulnathvc
You have to use QObject::connect method.
he *does* use this method... or where do you think does the "connect" in his code come from? the mistake is a simple typo.