Repost Parent / children / methods ? which way up ?
-
I am posting this in an attempt to RESOLVE these questions:
I have rebuild mY iTerator to scan for "actions".
The attached debug view shows [children] objects and they are of type QAction - that is NOT what I expect as action.The attached debug view shows [methods] and that is what I expect to process / execute. Obviously these are functions , theretofore there is no "type". ( i do not care to discus why I call them functions).
Please note casing QObject to QAction does not make the QObject executable action.
PLEASE NOTE THE SUBJect OF THIS POST.
I could use some real code help to fix this mess, I do not need RTFM, been asked / told before etc etc
If it is over your head or not in your job description to actually help me with code , PLEASE, stay out.
READ MY LIPS...
I am not being rude, just tired of all the psychoanalysis, AI robots , of subject comments , RTFM etc. Give yourself a break....If you actually read this far
YES, I WILL CLEAn UP ALL MY POSTS AFTER I GET This I RESOLVEDLocals
ChildrenCount 0 int
event @0x7fffffffca20 QCloseEvent
matchFound 0 int
mdiParent 0x330 QMdiSubWindow*
p "MainWindow_Bluetooth" MainWindow_Bluetooth
[QMainWindow] "MainWindow_Bluetooth" QMainWindow
[d] @0x555555c355d0 QMainWindowPrivate
[parent] @0x555555cee450 QMdiSubWindow
[children] <34 items> QList<QObject*>
[0] "_layout" QMainWindowLayout
[1] @0x555555caa220 QSerialPort
[2] "actionAbout" QAction
[3] "actionAboutQt" QAction
[4] "actionConnect" QAction
[5] "actionDisconnect" QAction
[6] "actionConfigure" QAction
[7] "actionClear" QAction
[8] "actionQuit" QAction
[9] "actionVirtual_serial_port" QAction
[10] "actionBluetooth_virtual_port" QAction
[11] "actionBluetooth" QAction
[12] "actionBluetooith_virtiual_port" QAction
[13] "actionBluetooth_service_enable" QAction
[14] "actionWinsow_control" QAction
[15] "actionWindoiw_control" QAction
[16] "actionTEST_tile" QAction
[17] "actionTEST_resize" QAction
[18] "actionTile_subwindows" QAction
[19] "actionCascade_subwindows" QAction
[20] "actionMaximize_current_subwindow" QAction
[21] "actionTEST" QAction
[22] "actionSubmenu_1" QAction
[23] "actionSubmenuy_2" QAction
[24] "actionClear_all_windoiws" QAction
[25] "actionClear_all_windiws" QAction
[26] "actionSerial_test" QAction
[27] "actionSerial_test_2" QAction
[28] "actionC_code_scan" QAction
[29] "actionSelect_MDI_subwindow_MDI_window_control" QAction
[30] "menuBar" QMenuBar
[31] "mainToolBar" QToolBar
[32] "statusBar" QStatusBar
[33] @0x555555c65090 QMdiArea
[properties] <0 items>
[methods] <21 items>
[0] closeEvent
[nameindex] 1
[type] slot
[argc] 1
[parameter] 119
[tag] 2
[flags] 10
[localindex] 0
[globalindex] 38
[1] TEST_Slot
[nameindex] 5
[type] <unknown>
[argc] 0
[parameter] 122
[tag] 2
[flags] 8
[localindex] 1
[globalindex] 39
[2] menuSelection_Array
[nameindex] 6
[type] <unknown>
[argc] 2
[parameter] 123
[tag] 2
[flags] 8
[localindex] 2
[globalindex] 40
[3] openSerialPort
[nameindex] 11
[type] <unknown>
[argc] 0
[parameter] 128
[tag] 2
[flags] 8
[localindex] 3
[globalindex] 41
[4] closeSerialPort
[nameindex] 12
[type] <unknown>
[argc] 0
[parameter] 129
[tag] 2
[flags] 8
[localindex] 4
[globalindex] 42
[5] about
[nameindex] 13
[type] <unknown>
[argc] 0
[parameter] 130
[tag] 2
[flags] 8
[localindex] 5
[globalindex] 43
[6] writeData
[nameindex] 14
[type] <unknown>
[argc] 1
[parameter] 131
[tag] 2
[flags] 8
[localindex] 6
[globalindex] 44
[7] readData
[nameindex] 16
[type] <unknown>
[argc] 0
[parameter] 134
[tag] 2
[flags] 8
[localindex] 7
[globalindex] 45
[8] handleError
[nameindex] 17
[type] <unknown>
[argc] 1
[parameter] 135
[tag] 2
[flags] 8
[localindex] 8
[globalindex] 46
[9] on_actionBluetooith_virtiual_port_triggered
[nameindex] 20
[type] <unknown>
[argc] 0
[parameter] 138
[tag] 2
[flags] 8
[localindex] 9
[globalindex] 47
[10] on_actionBluetooth_service_enable_triggered
[nameindex] 21
[type] <unknown>
[argc] 0
[parameter] 139
[tag] 2
[flags] 8
[localindex] 10
[globalindex] 48
[11] on_actionTEST_tile_triggered
[nameindex] 22
[type] <unknown>
[argc] 0
[parameter] 140
[tag] 2
[flags] 8
[localindex] 11
[globalindex] 49
[12] on_actionTile_subwindows_triggered
[nameindex] 23
[type] <unknown>
[argc] 0
[parameter] 141
[tag] 2
[flags] 8
[localindex] 12
[globalindex] 50
[13] on_actionCascade_subwindows_triggered
[nameindex] 24
[type] <unknown>
[argc] 0
[parameter] 142
[tag] 2
[flags] 8
[localindex] 13
[globalindex] 51
[14] on_actionMaximize_current_subwindow_triggered
[nameindex] 25
[type] <unknown>
[argc] 0
[parameter] 143
[tag] 2
[flags] 8
[localindex] 14
[globalindex] 52
[15] on_actionClear_all_windiws_triggered
[nameindex] 26
[type] <unknown>
[argc] 0
[parameter] 144
[tag] 2
[flags] 8
[localindex] 15
[globalindex] 53
[16] on_actionSerial_test_2_triggered
[nameindex] 27
[type] <unknown>
[argc] 0
[parameter] 145
[tag] 2
[flags] 8
[localindex] 16
[globalindex] 54
[17] on_actionConfigure_triggered
[nameindex] 28
[type] <unknown>
[argc] 1
[parameter] 146
[tag] 2
[flags] 8
[localindex] 17
[globalindex] 55
[18] on_actionConnect_triggered
[nameindex] 30
[type] <unknown>
[argc] 0
[parameter] 149
[tag] 2
[flags] 8
[localindex] 18
[globalindex] 56
[19] on_actionC_code_scan_triggered
[nameindex] 31
[type] <unknown>
[argc] 0
[parameter] 150
[tag] 2
[flags] 8
[localindex] 19
[globalindex] 57
[20] on_actionVirtual_serial_port_triggered
[nameindex] 32
[type] <unknown>
[argc] 0
[parameter] 151
[tag] 2
[flags] 8
[localindex] 20
[globalindex] 58
[extra]
Menu_Index 0 int
command 0x0 char*
index 8 int
index_sub 0 int
list_array @0x555555bd1320 QStringList[10]
m_TAB_CommonDebug "A_BT_TAB_DIALOG" A_BT_TAB_DIALOG
m_TAB_Connect 0x0 A_BT_TAB_DIALOG*
m_TAB_Ext 0x0 A_BT_TAB_DIALOG_EXT*
m_console @0x555555c37ef0 Console
m_mdiarea @0x555555c65090 QMdiArea
m_serial @0x555555caa220 QSerialPort
m_settings "SettingsDialog" SettingsDialog
m_settings_RFcomm 0x0 SettingsDialog_RFcomm*
m_status @0x555555c651b0 QLabel
m_ui @0x555555c35dc0 Ui::MainWindow_Bluetooth
mainAction @0x555555bd1478 QAction*[16]
result "" QString
staticMetaObject @0x7ffff7f03380 QMetaObject
subAction @0x555555bd1378 QAction*[16]
subMenu @0x555555bd13f8 QMenu*[16]
text " Parent console (case 7) " QString
verify @0x555555bd1520 QStringList[16]
pAction 0xffffef48b140 QDialog*
pActionChilren <0 items> QList<QAction*>
pItemObject @0x7fffffffc840 QObject
pWin @0x7fffffffc550 QWidget
textMatch "on_actionTile" QString
this "SettingsDialog" SettingsDialog
Inspector
Expressions
"(?<=\thci0 <no such value>
// subMenu[index] = subMenu[index] // ->addMenu(list[index] +
SERIAL_SETUP
SetupRun
endif// //subtempmenu = new QMenu(); // m_ui->actionConnect processAction qDebug().noquote() << text; Return Value Tooltip
ADDENDUM
here is my current code . modified for "action"void SettingsDialog::closeEvent( QCloseEvent* event ) { #ifdef RETILE text = "\t#ifdef RETILE \n"; text += "\t\t\tTRACE START Retile mdiArea subwindows .... "; text += " "; //text += " TASK initActionsConnections() "; text += Q_FUNC_INFO; text += QString::number(__LINE__); qDebug().noquote() << text; // text =" parent ???"; // text += parent()->objectName(); // qDebug().noquote() << text; #endif #ifdef BYPASS //event->accept(); // what does it do ?? emit PassMessage(text,0); // setup message passing QString for now connect(SDD,SIGNAL(PassMessage(QString,int)),this,SLOT(PostMessage(QString,int))); #endif #ifdef BYPOASS QWidget* p=this; while(p->parentWidget()) p = p->parentWidget(); // p need to be a QWidget, hence parentWidget() QList<QAction*> actions=p->actions(); for(QAction* action : actions) { // test for your action here } #endif { //scan for action code block( { // scan for objkect code blloc // Accept the event to allow the window to close event->accept(); // TOK // looking for action = tileSubwindows //QString textMmatch = "actionTile_subwindows"; QString textMatch = "on_actionTile"; // test code hete int matchFound = 0; QAction *pAction; QObject *pItemObject; //QObject* p=this; QWidget* p=this; #ifdef ITERATE text = " base class "; text += p->objectName(); qDebug().noquote() << text; #endif //while(p->parent()) while(p->parentWidget()) // p = p->parentWidget(); { // next parent widget //p = p->parent(); p = p->parentWidget(); #ifdef ITERATE text = " grand parent (up) class "; text += p->objectName(); qDebug().noquote() << text; #endif if(!p->objectName().isEmpty()) // skip no name { #ifdef ITERATE text = " grand parent (up) children classes "; text += p->objectName(); qDebug().noquote() << text; #endif //QObjectList pListChildren = p->children(); //QList<QAction*> pActionChilren = qobject_cast<QAction *>p->actions(); QList<QAction*> pActionChilren = p->actions(); //QAction *action = qobject_cast<QAction *>(pItemObject); auto ChildrenCount = pActionChilren.count(); if(ChildrenCount ) { // scan for actions foreach(auto *itemChild,pActionChilren) { if( itemChild->objectName().contains(textMatch)) { #ifdef ITERATE text = " \t\t\t *** found match "; text += itemChild->objectName(); qDebug().noquote() << text; //break; //continue; #endif pItemObject = itemChild; matchFound++; break; //continue; } else { text = " \tchild (action) not found continue search... "; } #ifdef ITERATE text += itemChild->objectName(); qDebug().noquote() << text; #endif } } if(!ChildrenCount) // correct place ?? { #ifdef ITERATE text = " \t\t\tno children / action count "; text += QString::number(ChildrenCount); qDebug().noquote() << text; #endif } if(matchFound) break; #ifdef ITERATE text += Q_FUNC_INFO; text += QString::number(__LINE__); qDebug().noquote() << text; #endif } } if(!matchFound) { text = " FAILED no match found "; qDebug().noquote() << text; } #ifdef ITERATE text = " DONE "; text += " action object name "; text += pItemObject->objectName(); qDebug().noquote() << text; //break; //continue; #endif #ifdef BYPASS QAction *action = qobject_cast<QAction *>(pItemObject); // ->trigger(10); #ifdef ITERATE text = " actinon name "; text += action->objectName(); qDebug().noquote() << text; #endif action->trigger(); #endif //return; } // scan for object code block } //scan for action code block { // scan for object code blloc // Accept the event to allow the window to close event->accept(); // TOK // looking for action = tileSubwindows QString textMmatch = "actionTile_subwindows"; //QString textMmatch = "on_actionTile"; // test code hete int matchFound = 0; QAction *pAction; QObject *pItemObject; QObject* p=this; #ifdef ITERATE text = " base class "; text += p->objectName(); qDebug().noquote() << text; #endif while(p->parent()) { // nnext parent p = p->parent(); #ifdef ITERATE text = " grand parent (up) class "; text += p->objectName(); qDebug().noquote() << text; #endif if(p) { #ifdef ITERATE text = " grand parent (up) children classes "; text += p->objectName(); qDebug().noquote() << text; #endif QObjectList pListChildren = p->children(); // scan for QObject foreach(auto *itemChild,pListChildren) { if( itemChild->objectName().contains(textMmatch)) { #ifdef ITERATE text = " \t\t\t *** found match "; text += itemChild->objectName(); qDebug().noquote() << text; //break; //continue; #endif pItemObject = itemChild; matchFound++; break; //continue; } else { text = " child (object) not found continue search... "; } #ifdef ITERATE text += itemChild->objectName(); qDebug().noquote() << text; #endif } if(matchFound) break; #ifdef ITERATE text += Q_FUNC_INFO; text += QString::number(__LINE__); qDebug().noquote() << text; #endif } } if(!matchFound) { text = " FAILED no match found "; qDebug().noquote() << text; } #ifdef ITERATE text = " DONE "; text += " action object name "; text += pItemObject->objectName(); qDebug().noquote() << text; //break; //continue; #endif QAction *action = qobject_cast<QAction *>(pItemObject); // ->trigger(10); #ifdef ITERATE text = " actinon name "; text += action->objectName(); qDebug().noquote() << text; #endif action->trigger(); //return; } // scan for object code block
-
// Iterate to the toplevel window QObject *topLevel = this; while (topLevel->parent()) topLevel = topLevel->parent(); // Find QAction children const QList<QAction *> actionList = topLevel->findChildren<QAction *>(Qt::FindChildrenRecursively); // Iterate over actions for (auto *action : actionList) { action->trigger(); // or another slot }
The funny thing about that code is: Nothing is new. All of it has been told you before.
Interaction in forums like this is much about reading:
- reading your own code, before you decide to post
- reading your own posts for typos and wrong statements, before you submit
- reading replies, to process information
- reading older posts and replies, to avoid double-posting
- reading the fantastic manuals (finally I found out, what the F means)
Interaction in forums like this is also about being humble and kind. If you remain polite and friendly, there's no need to write:
I am not being rude
(Pants on fire!)
-
Code is read much more often than it is written, so plan accordingly...
...the ratio of time spent reading versus writing is well over 10 to 1. We are constantly reading old code as part of the effort to write new code.
(Robert C. Martin, Clean Code: A Handbook of Agile Software Craftsmanship)
-
J J.Hilk marked this topic as a regular topic on
-
@J-Hilk said in Repost Parent / children / methods ? which way up ?:
(Robert C. Martin, Clean Code: A Handbook of Agile Software Craftsmanship)
Oh boy... Had to read this for my studies :D
Pretty helpful and well structured "guide" on how (not) to write code.