Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Forum Updated on Feb 6th

    Unsolved How to solve Object::connect: No such signal

    General and Desktop
    4
    12
    20148
    Loading More Posts
    • 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.
    • J
      jaouad100 last edited by

      I'm trying to display a sequence of images coming at 30 image per second in qt label but I'm getting that error of signal. This is my code:

      class MainWindow : public QMainWindow {
        Q_OBJECT
      public:
        MainWindow(int argc, char** argv, QWidget *parent = {});
        ~MainWindow() override;
      protected:
        void callBackColor(const sensor_msgs::ImageConstPtr& msg);
        void setImage(const QImage &);
        Q_SIGNAL void newImage(const QImage &);
      private:
        Ui::MainWindowDesign ui;
        ros::Subscriber sub;
      };
      
      MainWindow::MainWindow(int argc, char** argv, QWidget *parent)
          : QMainWindow(parent)
      {
        ui.setupUi(this);
        QObject::connect(this, SIGNAL(&MainWindow::newImage(const QImage &)), this, SLOT(&MainWindow::setImage(const QImage &)));
      
        ros::init(argc,argv,"MainWindow");
        ros::NodeHandle n;
        sub = n.subscribe("/usb_cam/image_raw", 1, &MainWindow::callBackColor, this);
      }
      
      void MainWindow::setImage(const QImage &image) {
        atui pix = QPixmap::fromImage(image);
        ui.imageLabel->setPixmap(pix);
      }
      
      void MainWindow::callBackColor(const sensor_msgs::ImageConstPtr& msg)
      {
        try {
          auto cv_ptr = cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::BGR8);
          QImage temp(&(msg->data[0]), msg->width, msg->height, 
          QImage::Format_RGB888);
          Q_EMIT newImage(temp);
        }
        catch (cv_bridge::Exception& e) {
          ROS_ERROR("cv_bridge exception: %s", e.what());
        }
      }
      

      I get that error Object::connect: No such signal qdude::MainWindow::&MainWindow::newImage(const QImage&*)
      and I tried to save QImage temp in a file and I get the frames I want. So the issue is as the error is saying, there's no signal!
      Do you have any idea where could be the issue?

      1 Reply Last reply Reply Quote 0
      • sierdzio
        sierdzio Moderators last edited by

        You are mixing old and new connect syntax.

        Either use this:

        // Old syntax
        connect(this, SIGNAL(MainWindow::newImage(const QImage)), this, SLOT(MainWindow::setImage(const QImage)));
        

        Or this:

        // New syntax:
        connect(this, &MainWindow::newImage, this, &MainWindow::setImage);
        

        I recommend using new syntax whenever possible.

        (Z(:^

        J 1 Reply Last reply Reply Quote 4
        • M
          mranger90 last edited by

          This post is deleted!
          1 Reply Last reply Reply Quote 0
          • J
            jaouad100 @sierdzio last edited by

            @sierdzio I was using the new version but I get the error of matching error: no matching function for call to ‘qdude::MainWindow::connect(qdude::MainWindow*, void (qdude::MainWindow::*)(const QImage&), qdude::MainWindow*, void (qdude::MainWindow::*)(const QImage&))’

            JonB 1 Reply Last reply Reply Quote 0
            • sierdzio
              sierdzio Moderators last edited by

              @jaouad100 said in How to solve Object::connect: No such signal:

              void setImage(const QImage &);

              Make this method as slot:

              protected slots:
                void setImage(const QImage &);
              

              (Z(:^

              J 1 Reply Last reply Reply Quote 0
              • J
                jaouad100 @sierdzio last edited by

                @sierdzio The same issue :/

                1 Reply Last reply Reply Quote 0
                • JonB
                  JonB @jaouad100 last edited by

                  @jaouad100 said in How to solve Object::connect: No such signal:

                  @sierdzio I was using the new version

                  If you say you are using the "new version" syntax, we would not expect to see SIGNAL() or SLOT().

                  Would you care to either confirm your code is still exactly as shown in your first post, or update it correctly?

                  J 1 Reply Last reply Reply Quote 0
                  • J
                    jaouad100 @JonB last edited by

                    @JonB I confirm that the code posted is the version I'm working on at the moment

                    JonB 1 Reply Last reply Reply Quote 0
                    • JonB
                      JonB @jaouad100 last edited by JonB

                      @jaouad100
                      Then I think (I am not a C++-er) you'll find that as @sierdzio wrote for the old syntax you need to remove the two & characters prior to MainWindow:: in both SIGNAL() & SLOT() (because they effectively put their own & in for you) ....

                      J 1 Reply Last reply Reply Quote 0
                      • J
                        jaouad100 @JonB last edited by

                        @JonB Yes I noticed that but it is not the issue

                        JonB 1 Reply Last reply Reply Quote 0
                        • JonB
                          JonB @jaouad100 last edited by JonB

                          @jaouad100
                          If it is not the issue, then why does your error message read:
                          qdude::MainWindow::&MainWindow::newImage(const QImage&*)
                          with that middling & in it? I believe it is....

                          If I wanted to use the old syntax, I would be writing:

                          QObject::connect(this, SIGNAL(newImage(const QImage &)), this, SLOT(setImage(const QImage &)));
                          

                          exactly as per e.g. http://doc.qt.io/qt-5/qobject.html#connect

                          J 1 Reply Last reply Reply Quote 3
                          • J
                            jaouad100 @JonB last edited by

                            @JonB Yes you're right. It was not only the reference because I tried without the reference but it didn't work but also the qualification on the names MainWindow:: I took it off and now it works, thanks!

                            1 Reply Last reply Reply Quote 1
                            • First post
                              Last post