[SOLVED] Emit signal not received
-
Hi, this is my first time trying out the emit signal, i want to pass it from one form to another on a push button so here's what I did.
secondform.h
@
signals:
void sendsignal(QString text);
@secondform.cpp
@
void secondform::on_pushButton_clicked()
{
QString signal= "sent";
emit sendsignal(signal);
qDebug()<<"Signal Generated";this->close();
}
@mainwindow.h
@
public slots:
void getsignal(QString text);
@mainwindow.cpp:
@
#include "secondform.h"connect(QWidget::window(),SIGNAL(sendsignal(QString)),this,SLOT(getsignal(QString)));
void MainWindow::getsignal(QString string)
{
qDebug()<<"Signal received"<<string;
}@
I get this message at runtime:
QObject::connect: No such signal MainWindow::sendsignal(QString) in ..
QObject::connect: (sender name: 'MainWindow')
QObject::connect: (receiver name: 'MainWindow')
Signal Generated -
QWidget::window() returns the Window of the Widget. I'm sure this will not have signal called sendSignal. First Argument for connect should be object of SendForm. Please make the appropriate correction for connect statement. Then it will work.
-
ok understand,
I changed and added a line but still doesn't work
mainwindow.cpp:
@
secondform* window = new secondform;
connect(window,SIGNAL(sendsignal(QString)),this,SLOT(getsignal(QString)));
@The value from getsignal function is not printed :(
-
How do you show secondform?
Do you use the window object that you allocated before connect ?
-
Window object which created just before the connect statement should emit the signal. Can you check where the 'window' object which created now, is emitting the signal ? Class does not emit the signal. Object emit the signals.
-
i've solved the problem by turning it around, calling the connect statement from secondform, passing the signal from secondform to mainwindow.
this works.secondform.cpp:
@
connect(this,SIGNAL(sendsignal(QString)),parentWidget(),SLOT(getsignal(QString)));
@Thank you.