Not able to connect signals and slots. [Qt programming in C++]

  c++, qt5

I wrote a basic C++ program for simulating the signal and slot process. I made a push button "button", a QVBoxLayout "layout". I added the button in the layout. Everything is fine till now. But when push button is made to connect by signal and slot, there’s are two problem/errors.

  1. "no instance of overloaded function "QObject::connect matches the argument list"."

  2. ‘QObject::connect’: none of the 3 overloads could convert all the argument types.

Question:
I am sure that there’s something missing, which I am not able to decipher. Here, the push button "button" has to invoke the function "connectFunc". Instead it gives me above two errors. How to make the button invoke the function?

This is my code.

#include "signalsslots.h"
#include <QtWidgets/QApplication>
#include<qpushbutton.h>
#include<qboxlayout.h>
#include<iostream>
using std::cout;
using std::endl;

void connectFunc()
{
    cout << endl << "connected " << endl;
}

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QPushButton* button = new QPushButton("Press Here");
    QAction* bAction = new QAction;
    button->addAction(bAction);
    QVBoxLayout* layout = new QVBoxLayout;
    layout->addWidget(button);
    
    
    //layout->SetFixedSize(200, 150);
    QObject::connect(bAction, SIGNAL(QPushButton::clicked()), &a,(connectFunc()));
    

    QWidget w;
    w.setLayout(layout);
    w.setWindowTitle("Signal and Slot Example !!!");
    w.show();
    return a.exec();
}

FYI, I am using VS 2019 for writing Qt widget applications.

Thanks in advance.

Source: Windows Questions C++

LEAVE A COMMENT