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

Confuse of Signal and Slot

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 765 Views 2 Watching
  • 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.
  • P Offline
    P Offline
    Phong
    wrote on last edited by
    #1

    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??

    1 Reply Last reply
    0
    • J Offline
      J Offline
      Jan-Willem
      wrote on last edited by
      #2

      Perhaps if you write it like this?

      connect(ui->BrowseBtn, SIGNAL(clicked()), this, SLOT(Browse()));
      
      1 Reply Last reply
      3
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by mrjj
        #3

        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

        1 Reply Last reply
        2
        • P Offline
          P Offline
          Phong
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0

          • Login

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