how to use "cascaded connect "?
-
Very basic , simple question
if have a "primary class / parent " with a "child secondary class ' as member
AND
the "parent class " has "parent connect code block " setup.How do I code the "child class" to use the "parent class " "connect"?
in pseudo code
parent class
{ parent connect code block}
child
{ child connect code block}
for example
child class -> button press -> execute parent "connect this..."
At preset all "action" is coded in parent:
connect(m_ui->actionConnect, &QAction::triggered, this, &MainWindow_Bluetooth::openSerialPort); connect(m_ui->actionDisconnect, &QAction::triggered, this, &MainWindow_Bluetooth::closeSerialPort); connect(m_ui->actionQuit, &QAction::triggered, this, &MainWindow_Bluetooth::close); connect(m_ui->actionConfigure, &QAction::triggered, m_settings, &SettingsDialog::show); connect(m_ui->actionClear, &QAction::triggered, m_console, &Console::clear); connect(m_ui->actionAbout, &QAction::triggered, this, &MainWindow_Bluetooth::about); connect(m_ui->actionAboutQt, &QAction::triggered, qApp, &QApplication::aboutQt);
Would adding / modifying the "actions" SOURCE in parent class be the correct way ?
Thanks
-
C Christian Ehrlicher moved this topic from Qt Creator and other tools on
-
@AnneRanch said in how to use "cascaded connect "?:
How do I code the "child class" to use the "parent class " "connect"?
"Use a connect"?
A connection is always a point-to-point connection between twoQObjects
.
You can't re-use the same connection somewhere else...
But I think I don't quite understand your "basic, simple question" here.If it's about where to make the connection...
This is not important and makes no difference. You establish the connection where you have access to signal sender and receiver.
So, "parent" is fine.If this was not your question, please be more accurate and explain further.
-
@Pl45m4 No, that was not my question.
After more research - I realized that I was correct - I need to modify my existing "parent" "connect" code - as said , it is now coded in my "parent ' object.
I could utilize "itelisense" BUT that is NOT what I would expect from tool likes QtCreator or QtDesigner.
QrDesigner lets me code "action" , but I have not found a way to actually build "connect " using QTDesigner.
( "edit action " dialog does not do much )Right now QtDesigner does not lead to logical build of "connect" function (macro ?) it lets me to "emulate" SLOT by using "goto slot " , BUT that builds the SLOT function in "child" object , triggered my "child" object. Somewhat awkward to keep track and maintain, and definitely not a single point for "connect " function.
.what I want is way to build "connect " "function" in parent .
That would satisfy the "single point " location.
As of now I have "SIGNAL/ SLOT " functionality AKA "connect" in both parent and child.
-
@AnneRanch
You wrote more text, but I don't understand a single line what you are saying or trying to do with your
QAction
...After more research - I realized that I was correct - I need to modify my existing "parent" "connect" code - as said , it is now coded in my "parent ' object.
What is "parent connect code"? Your
MainWindow
isparent
or what?I could utilize "itelisense" BUT that is NOT what I would expect from tool likes QtCreator or QtDesigner.
Then tell us what you expect.
QrDesigner lets me code "action" , but I have not found a way to actually build "connect " using QTDesigner.
( "edit action " dialog does not do much )QtDesigner "codes" nothing and QtDesigner also can't connect more than just the simple widget-to-widget-connections via auto-connect...
But this is evil and shouldn't be used in large projects. It only spreads bugs and confuses more than it is helpful. Also, it only works when using the standard signals and the "default" slot name "::on_<objectname>_<signal>()
".Right now QtDesigner does not lead to logical build of "connect" function (macro ?) it lets me to "emulate" SLOT by using "goto slot "
This is kinda true. QtDesigner cannot write
QObject::connect(a, &A::signal, b, &B::slot)
code for you.
Therefore read what I wrote above...BUT that builds the SLOT function in "child" object , triggered my "child" object. Somewhat awkward to keep track and maintain, and definitely not a single point for "connect " function.
QtDesigner adds the slots to the code file which belongs to the UI where you are currently in.
Good that you think that this is hard to maintain and feels awkward...Then, just one question... why you still want to do it like that?
You should know how the connection syntax works, even the "not new anymore" ;-)
Find your objects and write this one line as you already did here@AnneRanch said in how to use "cascaded connect "?:
connect(m_ui->actionConnect, &QAction::triggered, this, &MainWindow_Bluetooth::openSerialPort); connect(m_ui->actionDisconnect, &QAction::triggered, this, &MainWindow_Bluetooth::closeSerialPort); connect(m_ui->actionQuit, &QAction::triggered, this, &MainWindow_Bluetooth::close); connect(m_ui->actionConfigure, &QAction::triggered, m_settings, &SettingsDialog::show); connect(m_ui->actionClear, &QAction::triggered, m_console, &Console::clear); connect(m_ui->actionAbout, &QAction::triggered, this, &MainWindow_Bluetooth::about); connect(m_ui->actionAboutQt, &QAction::triggered, qApp, &QApplication::aboutQt);
All connections you do in QtDesigner are done via auto-connect or, if you go further and add new signals in QtDesigner to your widget, the connection is "set" in your UI file, like:
<sender>pushButton</sender> <signal>clicked()</signal> <receiver>MainWindow</receiver> <slot>Test()</slot>
So, no
connect(....)
code.Does anything of this answer your question? Because I still don't know what you mean by "cascaded connect" in the title and what you want to move where...
-
@Pl45m4 I am reluctant to continue this "discussion".
I have learn long time ago, well before binary age, that "one person can (safely) cross the street" , but TWO people can have up to FOUR "opinions" when crossing (the street) is safe.
It is obvious that you and I are trying to get something intelligent from this thread, however, we just cannot find common ground on HOW to resolve this.
It is my very common "problem" with English usage - discussions get sidetracked with "adjectives" and ignore "subject" , or home- made terminology . ( why we got stuck on common , accepted terminology as "parent " and "child" object' s?)OK, enough ranting....
I am not complaining , just need to get back to CODE "connect"' using available tools...
and AGAIN , I do not need more lectures HOW SIGNAL/SLOT works in Qt.Let me put it differently
"this is how to implement SIGNAL/SLOT in Qt...
step 1
.....
select "sender" using....step 2
select "receiver" using...
step 3
select "action" ( real Qt terminology ) using ....
.... -
@AnneRanch said in how to use "cascaded connect "?:
It is my very common "problem" with English usage - discussions get sidetracked with "adjectives" and ignore "subject" , or home- made terminology
It's not about your English... It's also not my native language.
I failed to understand what you are asking for and how one can help (in a technical sense).You wrote this code
@AnneRanch said in how to use "cascaded connect "?:
connect(m_ui->actionConnect, &QAction::triggered, this, &MainWindow_Bluetooth::openSerialPort); connect(m_ui->actionDisconnect, &QAction::triggered, this, &MainWindow_Bluetooth::closeSerialPort); connect(m_ui->actionQuit, &QAction::triggered, this, &MainWindow_Bluetooth::close); connect(m_ui->actionConfigure, &QAction::triggered, m_settings, &SettingsDialog::show); connect(m_ui->actionClear, &QAction::triggered, m_console, &Console::clear); connect(m_ui->actionAbout, &QAction::triggered, this, &MainWindow_Bluetooth::about); connect(m_ui->actionAboutQt, &QAction::triggered, qApp, &QApplication::aboutQt);
There's not more you need to know to connect two
QObjects
.@AnneRanch said in how to use "cascaded connect "?:
I am not complaining , just need to get back to CODE "connect"' using available tools...
and AGAIN , I do not need more lectures HOW SIGNAL/SLOT works in Qt.
Let me put it differently
"this is how to implement SIGNAL/SLOT in Qt...I mean, you need an object that emits a signal and another object which has a slot. The slot runs every time the signal is emitted (you know that already...).
And again, a connection made in QtDesigner doesn't produce aconnect
statement in your code. Unless they change something, it never will.Since you said, you don't need more lecture on how signals work, then explain what this is:
select "sender" using....
step 2
select "receiver" using...
step 3
select "action" ( real Qt terminology ) using ....Select where?! In QtDesigner?!
Do you want to emit a signal and let the receiver in its slot emit another signal to pass it on?!
Is this what you mean by "cascaded connect"? -
@AnneRanch said in how to use "cascaded connect "?:
How do I code the "child class" to use the "parent class " "connect"?
After reading this again... is it about INHERITING signals/slots from "parent" or a base class?
Your "parent" as you call it, has a signal
ping()
and is connected to a slot in widgetB
... and now you want to have the same connection toB
in achild
QObject ofA
?
That's not possible. Parent/Child are two differentQObjects
and you have to connect each independently.
You can inherit signals from a base class, but class inheritance is not the same thing as aQObject
Parent-child relation.... -
J JonB referenced this topic on