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. Appropriate places to connect button to slots
Forum Updated to NodeBB v4.3 + New Features

Appropriate places to connect button to slots

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 263 Views 1 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.
  • slava_xdS Offline
    slava_xdS Offline
    slava_xd
    wrote on last edited by
    #1

    I'm making a QT widgets application(it'll be opensource and I want to write it the cleaneast way possible) with visual studio I already have the whole UI set up using the QTDesigner. Now, my question is, now that I have the buttons and the functions, it's time to connect them via the connect function, like so:

    connect(ui.pushButton, SIGNAL(clicked()), this, SLOT(ButtonActionNow()));
    

    what i want to know is where should I set this up? I mean, should I call connect in the application constructor like:

    QtWidgetsApplication1::QtWidgetsApplication1(QWidget *parent)
        : QMainWindow(parent)
    {
        ui.setupUi(this);
        connect(ui.pushButton, SIGNAL(clicked()), this, SLOT(ButtonActionNow()));
    }
    
    or maybe inside the ui.setup function? What do people generally?
    
    Christian EhrlicherC 1 Reply Last reply
    0
    • slava_xdS slava_xd

      I'm making a QT widgets application(it'll be opensource and I want to write it the cleaneast way possible) with visual studio I already have the whole UI set up using the QTDesigner. Now, my question is, now that I have the buttons and the functions, it's time to connect them via the connect function, like so:

      connect(ui.pushButton, SIGNAL(clicked()), this, SLOT(ButtonActionNow()));
      

      what i want to know is where should I set this up? I mean, should I call connect in the application constructor like:

      QtWidgetsApplication1::QtWidgetsApplication1(QWidget *parent)
          : QMainWindow(parent)
      {
          ui.setupUi(this);
          connect(ui.pushButton, SIGNAL(clicked()), this, SLOT(ButtonActionNow()));
      }
      
      or maybe inside the ui.setup function? What do people generally?
      
      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @slava_xd said in Appropriate places to connect button to slots:

      or maybe inside the ui.setup

      Since this function is automatically generated this would be a wrong place.
      Connect them in the ctor for the ui stuff. And please don't use the old signal-slot syntax but the current one to get compile time errors instead at runtime.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      slava_xdS 1 Reply Last reply
      3
      • Christian EhrlicherC Christian Ehrlicher

        @slava_xd said in Appropriate places to connect button to slots:

        or maybe inside the ui.setup

        Since this function is automatically generated this would be a wrong place.
        Connect them in the ctor for the ui stuff. And please don't use the old signal-slot syntax but the current one to get compile time errors instead at runtime.

        slava_xdS Offline
        slava_xdS Offline
        slava_xd
        wrote on last edited by slava_xd
        #3

        @Christian-Ehrlicher how do i use the new syntax if I created all the buttons with the designer ?

        Christian EhrlicherC 1 Reply Last reply
        0
        • slava_xdS slava_xd

          @Christian-Ehrlicher how do i use the new syntax if I created all the buttons with the designer ?

          Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @slava_xd said in Appropriate places to connect button to slots:

          how do i use the new syntax if I created all the buttons with the designer ?

          Click on my link. I don't see any relation on where you created the widgets though.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          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