Button event with QT designer
-
Hello,
I am completetly new to qt designer and qt. I was wondering if there is a way in the designer to specify whigh function a button click should call. Or do I have to add that later in the code? -
Hello,
I am completetly new to qt designer and qt. I was wondering if there is a way in the designer to specify whigh function a button click should call. Or do I have to add that later in the code?Hi,
You do that later in the code using the new function pointer syntax.
-
@SGaist Thanks for the reply. I will have to look in how that works.
-
@SGaist Thanks for the reply. I will have to look in how that works.
@Rackelsack
@SGaist is the expert on Qt, but I am not sure why he has answered that you have to do this in code? Qt Creator/Designer has always allowed attachment of slots to (pre-existing) signals in the design editor, e.g. View > Views > Signal and Slots Editor. This could be used for theclicked
signal of aQPushButton
. Unless that has changed in a recent Creator release, but I would doubt that?However, there are so few advantages to doing it that way and several "gotchas" that we would recommend people consider only doing signal/slot connections in code as preferable. And sooner or later using Qt you will want to know how to do
connect()
s explicitly in code anyway. -
@Rackelsack
@SGaist is the expert on Qt, but I am not sure why he has answered that you have to do this in code? Qt Creator/Designer has always allowed attachment of slots to (pre-existing) signals in the design editor, e.g. View > Views > Signal and Slots Editor. This could be used for theclicked
signal of aQPushButton
. Unless that has changed in a recent Creator release, but I would doubt that?However, there are so few advantages to doing it that way and several "gotchas" that we would recommend people consider only doing signal/slot connections in code as preferable. And sooner or later using Qt you will want to know how to do
connect()
s explicitly in code anyway.@JonB Thanks for the info. The point is just that if I change the code and then later want to change something in the gui with the designer then the changes made will be lost. Or how does one usually handle changes made in the designer?
-
@JonB Thanks for the info. The point is just that if I change the code and then later want to change something in the gui with the designer then the changes made will be lost. Or how does one usually handle changes made in the designer?
@Rackelsack
Nope, that is exactly one of the "gotchas", I'm afraid. Designer doesn't adjust for renaming (unless that has changed). Hence suggestion that you just useconnect()
s in code, it isn't that important to be able to do in Designer.EDIT
Sorry, that's not the direction you are asking about. It's actually more likely to go wrong from a Designer change! You are going to have write code for everything else. If you rename or delete in Designer, you would have to adjust any code you had written (you will get compilation errors so you'll know). In principle, you will never lose anything in Designer from whatever you do in code. Designer creates a.ui
file,uic
gets run on it and produces code. So your code changes won't affect Designer. -
@Rackelsack
@SGaist is the expert on Qt, but I am not sure why he has answered that you have to do this in code? Qt Creator/Designer has always allowed attachment of slots to (pre-existing) signals in the design editor, e.g. View > Views > Signal and Slots Editor. This could be used for theclicked
signal of aQPushButton
. Unless that has changed in a recent Creator release, but I would doubt that?However, there are so few advantages to doing it that way and several "gotchas" that we would recommend people consider only doing signal/slot connections in code as preferable. And sooner or later using Qt you will want to know how to do
connect()
s explicitly in code anyway.@JonB said in Button event with QT designer:
@Rackelsack
@SGaist is the expert on Qt, but I am not sure why he has answered that you have to do this in code? Qt Creator/Designer has always allowed attachment of slots to (pre-existing) signals in the design editor, e.g. View > Views > Signal and Slots Editor. This could be used for theclicked
signal of aQPushButton
. Unless that has changed in a recent Creator release, but I would doubt that?However, there are so few advantages to doing it that way and several "gotchas" that we would recommend people consider only doing signal/slot connections in code as preferable. And sooner or later using Qt you will want to know how to do
connect()
s explicitly in code anyway.My answer might have been a bit terse here indeed but I would like to point that I didn't write that someone "has to do it by code" ;-)
Anyway, my point was that you are better off doing it in code to get better control of what is happening. Use designer for its design capabilities and for the rest, write code.
-
Ok thanks for all the replies. I will just code the connect(). Seems the simplest.