QObject::connect: signal not found in promoted widget with Lambda syntax
-
@VRonin
Something like this?connect(ui->productTree, static_cast<void (CustomTreeWidget::*)(QVector<int>)>(&CustomTreeWidget::deleteRequest), this, [=](QVector<int> uids) { qDebug() << "yeapp"; });
or
connect(ui->productTree, QOverload<QVector<int>>::of(&CustomTreeWidget::deleteRequest), this, [=](QVector<int> uids) { qDebug() << "yeapp"; });
Everything is same.
-
Quick test: Create a dummy class that inherits QObject (not a promoted QWidget!) and also give it a signal
void deleteRequest(QVector<int> uids)
. Instantiate this dummy class and try to connect this dummy signal to your lambda.Does it work?
-
@Taz742 said in QObject::connect: signal not found in promoted widget with Lambda syntax:
I dont know why but my CustomTreeWidget class have a UI
What do you mean? It is a GUI class, so it has a UI. Or do you mean it has ui member variable?
-
Hi,
have you registered QVector as a metatype - usingqRegisterMetaType
, to use it via Signal/Slots? -
Hi,
here's a dummy example:
#include <QtCore> #include <QtDebug> class MyClass : public QObject { Q_OBJECT signals: void deleteRequest(QVector<int> uids); void done(); public slots: void trigger() { emit deleteRequest(QVector<int>{1, 2, 3, 4}); QTimer::singleShot(1000, this, &MyClass::done); } }; int main(int argc, char** argv) { QCoreApplication app(argc, argv); MyClass mc; QTimer::singleShot(1000, &mc, &MyClass::trigger); QObject::connect(&mc, &MyClass::done, qApp, &QCoreApplication::quit); QObject::connect(&mc, &MyClass::deleteRequest, [](const QVector<int>& data) { qDebug() << data; }); return app.exec(); } #include "main.moc"
The content of the QVector is printed after one second and the application ends after another one. Does it work on your machine ?
-
@SGaist
I have a same situation in other class.
Can you check this example?#ifndef IMAGEWORKER_H #define IMAGEWORKER_H #include <QObject> #include "QDebug" #include "globalhelper.h" #include "QThread" #include "QMutex" #include "QFile" #include "QDir" #include "QCryptographicHash" #include "QByteArray" class ImageWorker : public QObject { Q_OBJECT public: explicit ImageWorker(QObject *parent = 0) { Q_UNUSED(parent); QThread *thread = new QThread; this->moveToThread(thread); connect(thread, &QThread::started, this, &ImageWorker::doWork); connect(this, &ImageWorker::finished, thread, &QThread::quit); connect(this, &ImageWorker::finished, this, &ImageWorker::deleteLater); connect(thread, &QThread::finished, thread, &QThread::deleteLater); thread->start(); } ~ImageWorker() { qDebug() << "ImageWorker deleted"; } signals: void finished(); public slots: void doWork() { emit finished(); } private: bool compareImages(const QByteArray &myImage, const QByteArray &serverImage) const { return myImage.toHex() == serverImage.toHex(); } QByteArray fileChecksum(const QByteArray &bytes, QCryptographicHash::Algorithm hashAlgorithm = QCryptographicHash::Md5) const { QCryptographicHash hash(hashAlgorithm); hash.addData(bytes); return hash.result(); } }; #endif // IMAGEWORKER_H
-
Since you implement the constructor in your derived class, why don't you call the base class constructor ?
What exact situation do you have ?
-
@SGaist said in QObject::connect: signal not found in promoted widget with Lambda syntax:
Since you implement the constructor in your derived class, why don't you call the base class constructor ?
I dont understood...
@SGaist said in QObject::connect: signal not found in promoted widget with Lambda syntax:
What exact situation do you have ?
QObject::connect: signal not found in ImageWorker QObject::connect: signal not found in ImageWorker
I am debuging it and its happen here:
connect(this, &ImageWorker::finished, thread, &QThread::quit); connect(this, &ImageWorker::finished, this, &ImageWorker::deleteLater);
-
explicit ImageWorker(QObject *parent = 0) : QObject(parent) { QThread *thread = new QThread; etc.
I removed
#include "globalhelper.h"
and it build successfully on macOS. -
@SGaist
There is great uncertainty... I changed@Taz742 said in QObject::connect: signal not found in promoted widget with Lambda syntax:
connect(this, &ImageWorker::finished, thread, &QThread::quit); connect(this, &ImageWorker::finished, this, &ImageWorker::deleteLater);
to
connect(this, SIGNAL(workerFinished()), thread, SLOT(quit())); connect(this, SIGNAL(workerFinished()), this, SLOT(deleteLater()));
its work...