Confuse of Signal and Slot

  • I wrote a simple function like this :

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    MainWindow::MainWindow(QWidget *parent) :
        ui(new Ui::MainWindow)
        connect(ui->BrowseBtn,&QPushButton::clicked,this, &MainWindow::Browse);
        QDir mDir("D:/Document");
        qDebug() << mDir.entryList();
        delete ui;
    void MainWindow::Browse(){
        qDebug() << "GG";

    and it works,
    However I change connect to

     connect(ui->BrowseBtn,SIGNAL(QPushButton::clicked()),this, SLOT(MainWindow::Browse()));

    it won't work!!! Can anyone tell me why??
    What's the different??

  • Perhaps if you write it like this?

    connect(ui->BrowseBtn, SIGNAL(clicked()), this, SLOT(Browse()));

  • Qt Champions 2017

    as @Jan-Willem writes you are not using the correct syntax

    for the OLD syntax, you do not append the class type inside the SLOT() and SIGNAL()

  • @Jan-Willem @mrjj
    OK, Thanks u guys, I know where the problem is now.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.