Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QObject::connect: signal not found in promoted widget with Lambda syntax
Forum Updated to NodeBB v4.3 + New Features

QObject::connect: signal not found in promoted widget with Lambda syntax

Scheduled Pinned Locked Moved Unsolved General and Desktop
17 Posts 6 Posters 4.0k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • VRoninV Offline
    VRoninV Offline
    VRonin
    wrote on last edited by
    #2

    Did you include the header of CustomTreeWidget in the ProductForm source file?

    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
    ~Napoleon Bonaparte

    On a crusade to banish setIndexWidget() from the holy land of Qt

    Taz742T 1 Reply Last reply
    0
    • VRoninV VRonin

      Did you include the header of CustomTreeWidget in the ProductForm source file?

      Taz742T Offline
      Taz742T Offline
      Taz742
      wrote on last edited by
      #3

      @VRonin
      Yes i have.

      Do what you want.

      1 Reply Last reply
      0
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #4

        There's nothing wrong in the code you posted, they only thing I can think of is try using QOverload<>::of in case that's the source of the problem

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        Taz742T 1 Reply Last reply
        2
        • VRoninV VRonin

          There's nothing wrong in the code you posted, they only thing I can think of is try using QOverload<>::of in case that's the source of the problem

          Taz742T Offline
          Taz742T Offline
          Taz742
          wrote on last edited by Taz742
          #5

          @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.

          Do what you want.

          1 Reply Last reply
          0
          • JKSHJ Offline
            JKSHJ Offline
            JKSH
            Moderators
            wrote on last edited by
            #6

            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?

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            Taz742T 1 Reply Last reply
            3
            • JKSHJ JKSH

              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?

              Taz742T Offline
              Taz742T Offline
              Taz742
              wrote on last edited by
              #7

              Guys... I dont know why but my CustomTreeWidget class have a UI. Should it be? :D

              Do what you want.

              jsulmJ 1 Reply Last reply
              0
              • Taz742T Taz742

                Guys... I dont know why but my CustomTreeWidget class have a UI. Should it be? :D

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #8

                @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?

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • J.HilkJ Offline
                  J.HilkJ Offline
                  J.Hilk
                  Moderators
                  wrote on last edited by
                  #9

                  Hi,
                  have you registered QVector as a metatype - using qRegisterMetaType, to use it via Signal/Slots?


                  Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                  Q: What's that?
                  A: It's blue light.
                  Q: What does it do?
                  A: It turns blue.

                  Taz742T 1 Reply Last reply
                  0
                  • J.HilkJ J.Hilk

                    Hi,
                    have you registered QVector as a metatype - using qRegisterMetaType, to use it via Signal/Slots?

                    Taz742T Offline
                    Taz742T Offline
                    Taz742
                    wrote on last edited by Taz742
                    #10

                    @J.Hilk
                    In main.cpp

                        qRegisterMetaType<QVector<int>>("QVector<int>");
                    

                    Now i am tryng but have a same situation.

                    Do what you want.

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #11

                      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 ?

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      Taz742T 2 Replies Last reply
                      1
                      • SGaistS SGaist

                        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 ?

                        Taz742T Offline
                        Taz742T Offline
                        Taz742
                        wrote on last edited by
                        #12

                        @SGaist
                        Yes its work. I am also tryed to create new project, move my CustomTreeWidget and work there.

                        Do what you want.

                        1 Reply Last reply
                        0
                        • SGaistS SGaist

                          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 ?

                          Taz742T Offline
                          Taz742T Offline
                          Taz742
                          wrote on last edited by Taz742
                          #13

                          @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
                          
                          

                          Do what you want.

                          1 Reply Last reply
                          0
                          • SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on last edited by
                            #14

                            Since you implement the constructor in your derived class, why don't you call the base class constructor ?

                            What exact situation do you have ?

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            Taz742T 1 Reply Last reply
                            0
                            • SGaistS SGaist

                              Since you implement the constructor in your derived class, why don't you call the base class constructor ?

                              What exact situation do you have ?

                              Taz742T Offline
                              Taz742T Offline
                              Taz742
                              wrote on last edited by Taz742
                              #15

                              @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);
                              

                              Do what you want.

                              1 Reply Last reply
                              0
                              • SGaistS Offline
                                SGaistS Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on last edited by
                                #16
                                explicit ImageWorker(QObject *parent = 0)
                                        : QObject(parent)
                                    {
                                        QThread *thread = new QThread;
                                       etc.
                                

                                I removed #include "globalhelper.h" and it build successfully on macOS.

                                Interested in AI ? www.idiap.ch
                                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                Taz742T 1 Reply Last reply
                                0
                                • SGaistS SGaist
                                  explicit ImageWorker(QObject *parent = 0)
                                          : QObject(parent)
                                      {
                                          QThread *thread = new QThread;
                                         etc.
                                  

                                  I removed #include "globalhelper.h" and it build successfully on macOS.

                                  Taz742T Offline
                                  Taz742T Offline
                                  Taz742
                                  wrote on last edited by Taz742
                                  #17

                                  @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...

                                  Do what you want.

                                  1 Reply Last reply
                                  0

                                  • Login

                                  • Login or register to search.
                                  • First post
                                    Last post
                                  0
                                  • Categories
                                  • Recent
                                  • Tags
                                  • Popular
                                  • Users
                                  • Groups
                                  • Search
                                  • Get Qt Extensions
                                  • Unsolved