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. Signal Slot Mechanism Error
Forum Updated to NodeBB v4.3 + New Features

Signal Slot Mechanism Error

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 330 Views
  • 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.
  • S Offline
    S Offline
    star673
    wrote on last edited by
    #1

    Hello all,

    I would like to make signal slot mechanism between two seperate classes. I have created "Bicycle" and "Car" classes. Here the codes.

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include "car.h"
    #include "bicycle.h"
    
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    ;
    
        car = new Car();
        bicycle = new Bicycle();
    
    
        connect(bicycle,&Bicycle::bicycleSignal(),car,&Car::carSlot());
    }
    
    
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    

    Classes are defined like below.

    #ifndef CAR_H
    #define CAR_H
    
    #include <QObject>
    
    class Car : public QObject
    {
        Q_OBJECT
    public:
        explicit Car(QObject *parent = nullptr);
    
    
    signals:
        void carSignal();
    
    
    public slots:
        void carSlot();
    };
    
    #endif // CAR_H
    
    #ifndef BICYCLE_H
    #define BICYCLE_H
    
    #include <QObject>
    
    class Bicycle : public QObject
    {
        Q_OBJECT
    public:
        explicit Bicycle(QObject *parent = nullptr);
    
    signals:
        void bicycleSignal();
    
    public slots:
        void bicycleSlot();
    };
    
    #endif // BICYCLE_H
    

    I have created the instances belong to Car and Bicycle classes. I got an error like " cannot call member function ‘void Bicycle::bicycleSignal()’ without object
    connect(bicycle,&Bicycle::bicycleSignal(),car,&Car::carSlot());
    ^"

    How can I solve this issue?

    JonBJ 1 Reply Last reply
    0
    • S star673

      Hello all,

      I would like to make signal slot mechanism between two seperate classes. I have created "Bicycle" and "Car" classes. Here the codes.

      #include "mainwindow.h"
      #include "ui_mainwindow.h"
      #include "car.h"
      #include "bicycle.h"
      
      
      MainWindow::MainWindow(QWidget *parent) :
          QMainWindow(parent),
          ui(new Ui::MainWindow)
      {
          ui->setupUi(this);
      ;
      
          car = new Car();
          bicycle = new Bicycle();
      
      
          connect(bicycle,&Bicycle::bicycleSignal(),car,&Car::carSlot());
      }
      
      
      
      MainWindow::~MainWindow()
      {
          delete ui;
      }
      
      

      Classes are defined like below.

      #ifndef CAR_H
      #define CAR_H
      
      #include <QObject>
      
      class Car : public QObject
      {
          Q_OBJECT
      public:
          explicit Car(QObject *parent = nullptr);
      
      
      signals:
          void carSignal();
      
      
      public slots:
          void carSlot();
      };
      
      #endif // CAR_H
      
      #ifndef BICYCLE_H
      #define BICYCLE_H
      
      #include <QObject>
      
      class Bicycle : public QObject
      {
          Q_OBJECT
      public:
          explicit Bicycle(QObject *parent = nullptr);
      
      signals:
          void bicycleSignal();
      
      public slots:
          void bicycleSlot();
      };
      
      #endif // BICYCLE_H
      

      I have created the instances belong to Car and Bicycle classes. I got an error like " cannot call member function ‘void Bicycle::bicycleSignal()’ without object
      connect(bicycle,&Bicycle::bicycleSignal(),car,&Car::carSlot());
      ^"

      How can I solve this issue?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @star673

      connect(bicycle,&Bicycle::bicycleSignal(),car,&Car::carSlot());

      Just by reading what the syntax for connect() tells/shows you what to write for the signal & slot methods. It does not tell you to put trailing () on those function references.

      S 1 Reply Last reply
      3
      • JonBJ JonB

        @star673

        connect(bicycle,&Bicycle::bicycleSignal(),car,&Car::carSlot());

        Just by reading what the syntax for connect() tells/shows you what to write for the signal & slot methods. It does not tell you to put trailing () on those function references.

        S Offline
        S Offline
        star673
        wrote on last edited by
        #3

        @JonB

        I couldn't just recognize it. Thank you.

        1 Reply Last reply
        1

        • Login

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