PDA

View Full Version : Signal slot don't work



cpuinthebrain
27th August 2016, 11:38
I have no idea why signal slot don't work.There is no error at all:


customers.h


signals:
void setFlagUp();


customers.cpp


void Customers::on_pushButtonCustomersDialogAdd_clicked ()
{
emit setFlagUp();
this->close();
}



mainwindow.h


private slots:
void setIsRecordSet();


mainwindow.cpp


Customers *cu = new Customers(this);
connect(cu, SIGNAL(setFlagUp()),this, SLOT(setIsRecordSet()));

void MainWindow::setIsRecordSet(){

qDebug() << "WORKS";
}

anda_skoa
27th August 2016, 13:03
That looks good.

I assume you have verified that both classes inherit QObject and have the Q_OBJECT macro in their class declaration.
And I assume you have checked that the slot that emits the signal is called.

But have you also checked the result of the connect()?

Cheers,
_

cpuinthebrain
27th August 2016, 21:15
I have correct inheritance of QObject, Q_OBJECT macro as well.The slot is called, but i don't know how to check the connection?

anda_skoa
27th August 2016, 22:57
The result or result type of a function in C++ is the string directly left of the function name in the documentation of a function.

For QObject::connect() that would be QMetaObject::Connection, a value that can be treated like a bool.

Cheers,
_

cpuinthebrain
28th August 2016, 07:26
In the moment of initialisation it returns false.

anda_skoa
28th August 2016, 08:37
Then you should have also gotten a warning on the application's output.
That usually contains information what is going wrong.

If you are using Qt5 you could also try the function pointer based connect and see if you get compile errors.

Cheers,
_