Click here to Skip to main content
15,886,919 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: get_string memory leak? Pin
Dave Kreskowiak6-Feb-24 12:22
mveDave Kreskowiak6-Feb-24 12:22 
GeneralRe: get_string memory leak? Pin
Mircea Neacsu6-Feb-24 12:28
Mircea Neacsu6-Feb-24 12:28 
AnswerRe: get_string memory leak? Pin
jschell6-Feb-24 5:02
jschell6-Feb-24 5:02 
GeneralRe: get_string memory leak? Pin
k50546-Feb-24 5:15
mvek50546-Feb-24 5:15 
GeneralRe: get_string memory leak? Pin
RedDk6-Feb-24 10:06
RedDk6-Feb-24 10:06 
GeneralRe: get_string memory leak? Pin
jschell7-Feb-24 5:22
jschell7-Feb-24 5:22 
GeneralRe: get_string memory leak? Pin
charlieg12-Feb-24 23:04
charlieg12-Feb-24 23:04 
Question"connect" with "lambda" C++ code analysis , please. Pin
Salvatore Terress3-Feb-24 15:01
Salvatore Terress3-Feb-24 15:01 
First - my apology for taking so much space, I promise to delete ALL after I get this solved - unless it is of benefit to forum...

Here is the current status of "main menu with sub menus "
using "connect" with lambda - it works only on FIRST menu.

I believe the sender and subsequent trigger are WRONG.
I am enclosing the code which creates
the " main menus with their associated sub menus ".
The code works as expected / desired.

The issue is using "connect" as a trigger..sub menu selection...








C++
{// menus processing
                                    // main memu primary loop is not array
                                    // main list is NOT an array
                                    for (index = 0; index < list.size(); ++index)
                                    {
                                        { // // main menu process block
                                            { // function
                                                // int subSize = 2;
                                                subMenu[index]  = m_ui->menuWindow_cpntrol;
                                                // adds main menu with arrows
                                                // triggers on hower
                                                subMenu[index] = subMenu[index]
                                                        ->addMenu(list[index] + " # " + QString::number(index));
                                                mainAction[index] = subMenu[index]->menuAction();  // TOK

                                                subSize = list_array[index].size();
                                                for (index_sub = 0; index_sub < subSize; ++index_sub)
                                                { // inner loop function block
                                                    { // process block
                                                        { // add sub menu
                                                            subAction[index_sub]= subMenu[index]->addAction(list_array[index][                      index_sub] + " #" + QString::number( index_sub));
                                                            subAction[index_sub]->setCheckable(true);
                                                        }// add sub menu
                                                    }// process block
                                                } // inner loop
                                            } // main menu process block

                                            // common stuff
                                            QAction* tempAction = new QAction(); //  text , this);
                                            tempAction->setCheckable(true);


                                            { // real connect block
                                                // connect to subMenu
                                                //connect(subMenu[index], &QMenu::triggered, this ,[=]() { this->processMenu_NoParameters() ;});
                                                //    connect(subMenu[1], &QMenu::triggered, this ,[=]() { this->processMenu(index,index_sub) ;});
                                            }

                                            { // connect block
                                                {// signal mapper code block

                                                } //   signal mapper code block
                                            }// connect block

                                            { // bypass block }
                                                //connect(subAction[index_sub],&QAction::triggered, [=]() {                                                               emit  this->processAction(index,index_sub);});

{}
                                            } // bypass block }
                                        }// main loop
                                    } // function block

                                    {
                                        //break;

                                    }
                                    //       connect(subAction[index_sub],&QAction::triggered, [=]() {
                                    //           emit  this->processAction(index,index_sub);});
                                }


Here is my current, working with FIRST menu code.
I do apology for "debug" junk code , it is a little hard to follow the real code.


C++
{
#ifdef LAMBDA
    text = "START TASK DEBUG lambda ... ";
    text += Q_FUNC_INFO;
    text += QString::number(__LINE__);
    qDebug() << text;
#endif

    // results
    int submenu_index = -1;
    int mainmenu_index= -1;

    QString mainMenu;


    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);
        //  TODO submenu_index = path;

#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 ;
            // who is parent widget
            parent=parent->parentWidget();
#ifdef LAMBDA
           qDebug()<<"TRACE  while first entry crasher ... "<< __LINE__ ;
#endif
            if(parent)
                {
#ifdef LAMBDA
           qDebug()<<"TRACE  parent widget (??) valid continue  ... "<< __LINE__ ;
#endif


                QMenu* menu=qobject_cast<QMenu*>(parent);
#ifdef LAMBDA
           qDebug()<<"TRACE  parent widget main menu (??)continue "<< __LINE__ ;
#endif
                int index=0;
                const QList<QAction*> actions=menu->actions();
#ifdef LAMBDA
           qDebug()<<"TRACE  parent widget main menu list (actions) continue "<< __LINE__ ;
#endif


                // all "window" menu ( action )
                // find current triggred menu
                for(const QAction *act : actions)
                    {
#ifdef LAMBDA
           qDebug()<<"TRACE  for(const QAction *act : actions) "<< __LINE__ ;
#endif
#ifdef LAMBDA
           qDebug()<<"TRACE  title (??) " << title << __LINE__ ;
#endif
#ifdef LAMBDA
           qDebug()<<"TRACE  act->text()==title  "<< act->text() << __LINE__ ;
#endif
                    if(act->text()==title)
                        {

#ifdef LAMBDA
           qDebug()<<"TRACE  main menu found act->text()==title  "<< act->text() << __LINE__ ;
#endif
                       //path +=QString("(%1)").arg(index);
                        path = QString("(%1)").arg(index);
                        // mainMenu = QString("%1").arg(index);
#ifdef LAMBDA
                        //qDebug()<< "mainMenu index " << mainMenu;
                        //mainmenu_index = QString::number(mainMenu);

#endif


#ifdef LAMBDA
                        qDebug()<<"HERE   path (main menu -> sub menu) "<< path ;
#endif
                        goto TEMP_LABEL;
                        // ??break;
                        }
#ifdef LAMBDA
           qDebug()<<"TRACE  "<< __LINE__ ;
#endif

                    index++;
                    }
                }
            } // while loop
TEMP_LABEL:        qDebug()<<" FINAL  (??) "<< path;

    }// lambda
    );

    QString::number(__LINE__);
    //mainmenu_index = QString::number(mainMenu);


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


'

Here is more junk - actual debug output when first "main menu" and its "first sub menu " is selected - by triggering on first sub menu.


19:53:10: 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.
"START TASK DEBUG lambda ... int MainWindow_Bluetooth::setupLambda()89"
 index_sub  0
"END TASK DEBUG lambda... int MainWindow_Bluetooth::setupLambda()213"
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  while first entry crasher ...  138
TRACE  parent widget (??) valid continue  ...  143
TRACE  parent widget main menu (??)continue  149
TRACE  parent widget main menu list (actions) continue  154
TRACE  for(const QAction *act : actions)  163
TRACE  title (??)  "terminal      # 0" 166
TRACE  act->text()==title   "Tile subwindows " 169
TRACE   194
TRACE  for(const QAction *act : actions)  163
TRACE  title (??)  "terminal      # 0" 166
TRACE  act->text()==title   "Cascade subwindows " 169
TRACE   194
TRACE  for(const QAction *act : actions)  163
TRACE  title (??)  "terminal      # 0" 166
TRACE  act->text()==title   "Maximize current subwindow " 169
TRACE   194
TRACE  for(const QAction *act : actions)  163
TRACE  title (??)  "terminal      # 0" 166
TRACE  act->text()==title   "" 169
TRACE   194
TRACE  for(const QAction *act : actions)  163
TRACE  title (??)  "terminal      # 0" 166
TRACE  act->text()==title   "" 169
TRACE   194
TRACE  for(const QAction *act : actions)  163
TRACE  title (??)  "terminal      # 0" 166
TRACE  act->text()==title   "terminal      # 0" 169
TRACE  main menu found act->text()==title   "terminal      # 0" 175
HERE   path (main menu -> sub menu)  "(5)"
 FINAL  (??)  "(5)"
19:53:27: /mnt/A_BT_DEC10/BT__PROGRAMS/A_JAN11/A_BT_LIBRARY/mdi/mdi exited with code 0




Here is the failure when ANY main menu , with exception of first one , is used.

That points to probable cause - wrong sender....

19:31:40: 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.
"START TASK DEBUG lambda ... int MainWindow_Bluetooth::setupLambda()89"
 index_sub  0
"END TASK DEBUG lambda... int MainWindow_Bluetooth::setupLambda()213"
19:31:54: /mnt/A_BT_DEC10/BT__PROGRAMS/A_JAN11/A_BT_LIBRARY/mdi/mdi exited with code 0

SuggestionRe: "connect" with "lambda" C++ code analysis , please. Pin
k50543-Feb-24 15:55
mvek50543-Feb-24 15:55 
GeneralRe: "connect" with "lambda" C++ code analysis , please. Pin
Salvatore Terress3-Feb-24 16:44
Salvatore Terress3-Feb-24 16:44 
GeneralRe: "connect" with "lambda" C++ code analysis , please. Pin
k50544-Feb-24 4:34
mvek50544-Feb-24 4:34 
GeneralRe: "connect" with "lambda" C++ code analysis , please. Pin
Salvatore Terress4-Feb-24 4:49
Salvatore Terress4-Feb-24 4:49 
GeneralRe: "connect" with "lambda" C++ code analysis , please. Pin
k50544-Feb-24 5:30
mvek50544-Feb-24 5:30 
GeneralRe: "connect" with "lambda" C++ code analysis , please. Pin
Salvatore Terress4-Feb-24 13:36
Salvatore Terress4-Feb-24 13:36 
GeneralRe: "connect" with "lambda" C++ code analysis , please. Pin
k50545-Feb-24 4:25
mvek50545-Feb-24 4:25 
GeneralRe: "connect" with "lambda" C++ code analysis , please. Pin
Salvatore Terress5-Feb-24 6:30
Salvatore Terress5-Feb-24 6:30 
GeneralRe: "connect" with "lambda" C++ code analysis , please. Pin
Richard MacCutchan4-Feb-24 6:16
mveRichard MacCutchan4-Feb-24 6:16 
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 

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.