Click here to Skip to main content
15,881,767 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: "connect" with "lambda" C++ code analysis , please. Pin
jschell5-Feb-24 5:33
jschell5-Feb-24 5:33 
GeneralRe: "connect" with "lambda" C++ code analysis , please. Pin
Salvatore Terress5-Feb-24 6:38
Salvatore Terress5-Feb-24 6:38 
GeneralRe: "connect" with "lambda" C++ code analysis , please. Pin
k50545-Feb-24 7:10
mvek50545-Feb-24 7:10 
GeneralRe: "connect" with "lambda" C++ code analysis , please. Pin
jschell6-Feb-24 4:40
jschell6-Feb-24 4:40 
Questionstrlen innards Pin
mike74112-Feb-24 12:02
mike74112-Feb-24 12:02 
AnswerRe: strlen innards Pin
Richard MacCutchan2-Feb-24 21:52
mveRichard MacCutchan2-Feb-24 21:52 
AnswerRe: strlen innards Pin
jschell5-Feb-24 5:58
jschell5-Feb-24 5:58 
QuestionMissing "type specifier " ? Pin
Salvatore Terress2-Feb-24 5:37
Salvatore Terress2-Feb-24 5:37 
More update
Found the crasher - wrong "exit" from "for" loop looking for main menu.

Having issues (expected ) using other than first main menu...



UPDATE

I am posting this to show SOME progress.
I did pepper the original with handful of "debug"...
( I need to add comments about what the code does...)

So far it works with main menu = 0 and all its sub menus - SUCCESS.

I got the sub menu index - so part of my goal is done.

Now I need to find the "main menu" index and then find the "crasher"..

BTW the author deserves LARGE credit for the code..


C++
// NOTES placed AFTER menu / submenu
int  MainWindow_Bluetooth::setupLambda ( void )
{
#ifdef LAMBDA
    text = "START TASK DEBUG lambda ... ";
    text += Q_FUNC_INFO;
    text += QString::number(__LINE__);
    qDebug() << text;
#endif
    QObject obj;

    qDebug() << " index_sub " << index_sub ; // bogus
    obj.connect(subMenu[index_sub],&QMenu::triggered,subMenu[index_sub  ],[](QAction* action)
// obj.connect(subAction[index_sub],QAction::triggered(bool),subAction[index_sub ],[](QAction* action)

    {// lambda

        QString path=action->text();

#ifdef LAMBDA
       qDebug() << "TEST need index ?? " << path;
       qDebug()<<"path (sub menu trigger ) "<< path ;
#endif
        QWidget* parent=action->parentWidget();
        // !!!!  submenu  trigger index   !!!
        path = QString("(%1)").arg(parent->actions().indexOf(action));
        //path += QString("(%1)").arg(parent->actions().indexOf(action));
        //qDebug() << " index ??" << parent->actions().indexOf(actions);

#ifdef LAMBDA
        qDebug()<<"path (sub menu ) with index TOK  "<< path ;
#endif
        while(parent)
            {
            // main menu
            QMenu* menu=qobject_cast<QMenu*>(parent);
            QString title=menu->title();
 #ifdef LAMBDA
            qDebug()<<"title (main menu )  "<< title ;
#endif
            path+="->"+title;
            qDebug()<<"path (title) "<< path ;
            // ??
            parent=parent->parentWidget();
#ifdef LAMBDA
           qDebug()<<"TRACE  "<< __LINE__ ;
#endif
            if(parent)
                {
                QMenu* menu=qobject_cast<QMenu*>(parent);
#ifdef LAMBDA
           qDebug()<<"TRACE  "<< __LINE__ ;
#endif
                int index=0;
                const QList<QAction*> actions=menu->actions();
                for(const QAction *act : actions)
                    {
#ifdef LAMBDA
           qDebug()<<"TRACE  "<< __LINE__ ;
#endif

                    if(act->text()==title)
                        {
                        path+=QString("(%1)").arg(index);
#ifdef LAMBDA
                        qDebug()<<"path (main menu -> sub menu) "<< path ;
#endif
                        break;
                        }
#ifdef LAMBDA
           qDebug()<<"TRACE  "<< __LINE__ ;
#endif

                    index++;
                    }
                }
            }
        qDebug()<<" FINAL  (??) "<< path;

    }// lambda
    );
#ifdef LAMBDA
    text = "END TASK DEBUG lambda... ";
    text += Q_FUNC_INFO;
    text += QString::number(__LINE__);
    qDebug() << text;
#endif
    return 0;
}



OUTPUT

11:57:03: Starting /mnt/A_BT_DEC10/BT__PROGRAMS/A_JAN11/A_BT_LIBRARY/mdi/mdi...
Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.
QObject::connect(QAction, Unknown): invalid nullptr parameter
"START TASK DEBUG lambda ... int MainWindow_Bluetooth::setupLambda()89"
 index_sub  0
"END TASK DEBUG lambda... int MainWindow_Bluetooth::setupLambda()167"
TEST need index ??  "SubWindow LOCAL terminal all options          #0"
path (sub menu trigger )  "SubWindow LOCAL terminal all options          #0"
path (sub menu ) with index TOK   "(0)"
title (main menu )   "terminal      # 0"
path (title)  "(0)->terminal      # 0"
TRACE   128
TRACE   134
TRACE   141
TRACE   153
TRACE   141
TRACE   153
TRACE   141
TRACE   153
TRACE   141
TRACE   153
TRACE   141
TRACE   153
TRACE   141
path (main menu -> sub menu)  "(0)->terminal      # 0(5)"
title (main menu )   "Window control"
path (title)  "(0)->terminal      # 0(5)->Window control"
TRACE   128
TRACE   134
11:57:22: /mnt/A_BT_DEC10/BT__PROGRAMS/A_JAN11/A_BT_LIBRARY/mdi/mdi crashed.






I do not get what is missing - the error "points" at "action".

Code snippet :


C++
QObject::connect(&MainWindow_Bluetooth::subMenu,&QMenu::triggered,&MainWindow_Bluetooth::subMenu,[](QAction* action)
{// lambda
    QString path=action->text();

QWidget* parent=action->parentWidget();
path+=QString("(%1)").arg(parent->actions().indexOf(action));

while(parent)
    {
    QMenu* menu=qobject_cast<QMenu*>(parent);
    QString title=menu->title();
    path+="->"+title;
    parent=parent->parentWidget();

    if(parent)


ERROR :


/mnt/A_BT_DEC10/BT__PROGRAMS/A_JAN11/A_BT_LIBRARY/terminal_Bluetooth/mainwindow_Bluetooth_copy.cpp:42: error: C++ requires a type specifier for all declarations
mainwindow_Bluetooth_copy.cpp:42:10: error: C++ requires a type specifier for all declarations
QObject::connect(&MainWindow_Bluetooth::subMenu,&QMenu::triggered,&MainWindow_Bluetooth::subMenu,[](QAction* action)
         ^


modified 3-Feb-24 16:02pm.

AnswerRe: Missing "type specifier " ? Pin
Mircea Neacsu2-Feb-24 5:52
Mircea Neacsu2-Feb-24 5:52 
AnswerRe: Missing "type specifier " ? Pin
jschell2-Feb-24 5:53
jschell2-Feb-24 5:53 
GeneralRe: Missing "type specifier " ? Pin
k50542-Feb-24 7:28
mvek50542-Feb-24 7:28 
AnswerRe: Missing "type specifier " ? Pin
RedDk2-Feb-24 7:39
RedDk2-Feb-24 7:39 
GeneralRe: Missing "type specifier " ? Pin
Salvatore Terress2-Feb-24 8:02
Salvatore Terress2-Feb-24 8:02 
GeneralRe: Missing "type specifier " ? Pin
Salvatore Terress2-Feb-24 9:05
Salvatore Terress2-Feb-24 9:05 
GeneralRe: Missing "type specifier " ? Pin
Mircea Neacsu2-Feb-24 10:44
Mircea Neacsu2-Feb-24 10:44 
GeneralRe: Missing "type specifier " ? Pin
k50542-Feb-24 12:15
mvek50542-Feb-24 12:15 
GeneralRe: Missing "type specifier " ? Pin
Salvatore Terress2-Feb-24 15:28
Salvatore Terress2-Feb-24 15:28 
QuestionPreTranslateMessage method is missing Pin
utcode1-Feb-24 16:35
utcode1-Feb-24 16:35 
AnswerRe: PreTranslateMessage method is missing Pin
Victor Nijegorodov1-Feb-24 22:41
Victor Nijegorodov1-Feb-24 22:41 
QuestionPrinting to exact coordinates on paper or lottery tickets Pin
inlandchris11-Feb-24 6:31
inlandchris11-Feb-24 6:31 
AnswerRe: Printing to exact coordinates on paper or lottery tickets Pin
Gerry Schmitz1-Feb-24 7:56
mveGerry Schmitz1-Feb-24 7:56 
GeneralRe: Printing to exact coordinates on paper or lottery tickets Pin
inlandchris11-Feb-24 15:12
inlandchris11-Feb-24 15:12 
Questionhow to bypass loop ? Pin
Salvatore Terress28-Jan-24 6:10
Salvatore Terress28-Jan-24 6:10 
AnswerRe: how to bypass loop ? Pin
k505428-Jan-24 6:30
mvek505428-Jan-24 6:30 
QuestionRe: how to bypass loop ? Pin
CPallini28-Jan-24 21:02
mveCPallini28-Jan-24 21:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.