where is my C code?
-
After muddling thru add of new "connect" using "Signal and slot editor " in QtDesigner I am trying to physically verify results in my C code .
Any suggestion how ? (search for added "action" ?)
PS
Unless it is "automatic" (?) I have not found the actual "save added " by .......... -
Christian Ehrlicher Lifetime Qt Championreplied to Anonymous_Banned275 on last edited by Christian Ehrlicher
@AnneRanch There is no c code anywhere. As you already know
uic.exe
creates theui_<foo>.h
file out of the<foo>.ui
file which contains the corresponding c++ code. -
@Christian-Ehrlicher ...now you tell me that "connect" is in yet another place - to maintain.
Nice .
Especially when such place is NOT accessible (directly) via Project view.
So what is expected, if any , way to debug // verify the QtDesigner " signal and slot editor " actual code ?I can verify simple "generate SIGNAL and change state of "
radio button" in SAME object. Big deal...PS
I obviously should not tell you how to express yourself , but in the future I would appreciate NOT teling me what I know... it sounds like you are grading my knowledge. But you are free to ignore my request. -
@AnneRanch said in where is my C code?:
So what is expected, if any , way to debug // verify the QtDesigner " signal and slot editor " actual code ?
As I already said - compile the ui file with uic and look into the generated header file.
-
@AnneRanch
Not sure what you are asking or looking for. But if you are asking: when I do a signal-slot connection in Creator/Designer does it generate an explicitconnect(...)
statement the answer it does NOT, so if you search anywhere for that you will not find it.TL;DR: There is no explicit
connect()
statement produced in any code. Instead the generatedui_...h
file calls void QMetaObject::connectSlotsByName(QObject *object) to do theconnect()
s "behind the scenes", by object name and method name spelling.- Everything you do in Designer goes into the saved
.ui
file, nowhere else. By all means look at it in a text editor. This includes any signal-slots you set up. In https://forum.qt.io/topic/155704/how-to-use-cascaded-connect/4 @Pl45m4 answered that in the.ui
file it just produces:
<sender>pushButton</sender> <signal>clicked()</signal> <receiver>MainWindow</receiver> <slot>Test()</slot>
Just that. Note that there is no
connect()
statement.- Everything that is in the
.ui
file gets turned into code byuic
in file nameui_....h
, in the build output directory, nowhere else. By all means look at it in a text editor. Even then for Designer signal/slot connections it does NOT generate an explicitconnect(...)
statement, which you would do if you wrote it yourself. Instead it does two things:
- It generates a method with name
ClassName::on_<objectname>_<signal>()
, soMainWindow::on_pushButton_clicked()
for above example. - It generates code (at the end of
setupUi()
) which calls connectSlotsByName(). This is the "magic" function which does theconnect()
s, in internal Qt code which you cannot see:
Searches recursively for all child objects of the given object, and connects matching signals from them to slots of object that follow the following form:
void on_<object name>_<signal name>(<signal parameters>);
I trust that is as clear as anyone can explain it. As I say, if you are looking for an explicit
connect()
statement anywhere for the signals-slots you set up from Designer you simply won't find one. It just relies on the actual spelling of the slot name and the call toconnectSlotsByName()
.This is also one of the many reasons why Designer's signal-slot connections are fragile and not recommended for "serious" development. A simple change like altering a widget's name, or other things, can "break" this name-relationship and cause a connection not to be set up by
connectSlotsByName()
.Finally, it is not possible to "physically verify results in my C code" that your Designer signal-slot is correct. Because it does not do an explicit
connect()
but relies instead on naming of widgets and slot function. - Everything you do in Designer goes into the saved
-
I don't think that any of these explanations, either here not in the other topic, will lead somewhere -.-'
OP already knows how to write the connect statement herself, but still sticks to the (bad and limited) QtDesigner "coding"... and is then wondering and ranting that some things don't work (which never will by design). -
@Pl45m4 I may have neglected mentioning ONE part of the task - the signal ( as in generic term, not SIGNAL as defined by Qt) originates from QMainWindow "menu (bar) ".
There it is termed as "action" , but its function is still same as PLAIN "connect".In my view this all boils down to establish some logical way of following and finishing the task - from source to sink/load , and the descriptions used in various doc just does not make it logical to follow the flow from one tool to another.
-
@Pl45m4 said in where is my C code?:
but still sticks to the (bad and limited) QtDesigner "coding"... and is then wondering and ranting that some things don't work (which never will by design).
I am offended , just kidding, but dare you to send this to Alex.
It all does work , once one gets pass the UNDOCUMENTED " "click this to get that " ...
My uneducated guess is - Qt inc have no way to make sure "linked documents " follow some kind of common path.
As far as I can tell, this discussion , based on "callback AKA SIGNAL/ SLOT" shows that very clearly.
Life would be boring if it all works " out of the box"... -
@AnneRanch said in where is my C code?:
I may have neglected mentioning ONE part of the task - the signal ( as in generic term, not SIGNAL as defined by Qt) originates from QMainWindow "menu (bar) ".
There it is termed as "action" , but its function is still same as PLAIN "connect".A signal is a signal and an action is an action.
AQAction
fires a signal likeQAction::triggered
upon activation (e.g. you click the action widget button associated with your menuBar action). Then you can connect a function / slot to that signal.
I don't understand why most Qt users think Qt is well documentated, while you always think it's not...@AnneRanch said in where is my C code?:
It all does work , once one gets pass the UNDOCUMENTED " "click this to get that " ...
Yes, there is room for improvements in QtDesigner, but, actually, nobody uses this s#!%t, because it's more or less a demo feature.
You can't put these tightly to the objectname coupled, "no code" connections in real code. Everything will break once you rename or re-organize something.
And even if someone, who knows C++ well, but doesn't know Qt, reads your code using the "connect(....)" statement, one will still understand what's going on and why things happen.
But these "behind-the-scene" connections made by QtDesigner and setup byQMetaObject::connectSlotsByName
in auto-connection manner, are a plain to track down, if you don't know that they exist.
And that's just one of (many many) other cases, where you shouldn't "write" your program by clicking buttons in QtDesigner.I think you've learned something out of all these topics in all these years here in the forum... and you are still working on the same project.
My well-meant advice:
Go through your code (your "UIs") and start to write a connect-statement for every connection. It's just one line. Then you can get rid of all that bs integrated in your UI files, which will come to its limits and where you, at some point, just can't do stuff (by design) anymore.
If you want to use QtDesigner to "design" (drag widgets around) your GUI, fine. It's a valid alternative over creating simple widgets and layouts by code.
But trying to code as less as possible and abusing QtDesigner "features" as much as possible won't work all the time, as you might have noticed.
You know the basic things and how to code (as it has already been explained to you several times)As the Nike slogan says: Just do it ;-)
Trust me, it will pay off.
Over and out. ;-)Edit:
So that this post does not remain more or less off-topic, the answer to the question in the title is: Nowhere, there is no code.
-
@Pl45m4 said in where is my C code?:
So that this post does not remain more or less off-topic, the answer to the question in the title is: Nowhere, there is no code.
Even though you can rely on connectSlotsByName, the screenshot in the original post shows using the Signals and Slots Editor. In that case I agree with @Christian-Ehrlicher that there should be C++ code in the
ui_<foo>.h
file after runninguic.exe
on the corresponding ui file. -
But that's nothing you can really use or modify since it's generated and overwritten when you change something.
I think the whole topic was about the question why QtDesigner can't put aconnect(......)
, for example in yourMainWindow
class -
@Pl45m4 This "discussion" did provide SOME help in implementing / tracking basic SIGNAL / SLOT (concept) as defined by Qt.
And I do appreciate that.However, it got diverted off the original post and is no longer of (any) help TO ME personally.
It is up to the forum users to continue with various speculations and terminology variations.
I am "over and out "....
-