Appropriate places to connect button to slots
-
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?
-
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?
@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_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.@Christian-Ehrlicher how do i use the new syntax if I created all the buttons with the designer ?
-
@Christian-Ehrlicher how do i use the new syntax if I created all the buttons with the designer ?
@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.