Confuse of Signal and Slot



  • I wrote a simple function like this :

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        connect(ui->BrowseBtn,&QPushButton::clicked,this, &MainWindow::Browse);
        QDir mDir("D:/Document");
        qDebug() << mDir.entryList();
    
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    void MainWindow::Browse(){
        ui->FileShow->setText("GG!");
        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()

    http://doc.qt.io/qt-5/signalsandslots-syntaxes.html



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