Missing "type specifier " ?
-
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..
// 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(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(parent);
#ifdef LAMBDA
qDebug()<<"TRACE "<< __LINE__ ;
#endif
int index=0;
const QList actions=menu->actions();
for(const QAction *act : actions)
{
#ifdef LAMBDA
qDebug()<<"TRACE -
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..
// 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(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(parent);
#ifdef LAMBDA
qDebug()<<"TRACE "<< __LINE__ ;
#endif
int index=0;
const QList actions=menu->actions();
for(const QAction *act : actions)
{
#ifdef LAMBDA
qDebug()<<"TRACENo, the error is on
QObject::connect(...
. You cannot call a member function of a class(*). You have to insantiate an object of the class and call the member function on that object. Something like:QObject obj(/*constructor params*/);
obj.connect(/*...*/);[*] Unless the member function is a static member function. I doubt that is the case here.
Mircea
-
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..
// 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(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(parent);
#ifdef LAMBDA
qDebug()<<"TRACE "<< __LINE__ ;
#endif
int index=0;
const QList actions=menu->actions();
for(const QAction *act : actions)
{
#ifdef LAMBDA
qDebug()<<"TRACE -
Certainly looks to me that at a minimum you are missing a paren in the first line/statement.
That's what I thought too, but then I saw the comment
//lambda
just after the opening brace. I think that the following code is all a lambda expression as a parameter to the QObject::connect() call. I think the OP could have cleaned up the submission with something likeQObject::connect(&MainWindow_Bluetooth::subMenu,&QMenu::triggered,&MainWindow_Bluetooth::subMenu,[](QAction* action){ /* lamda, body omitted */ });
"A little song, a little dance, a little seltzer down your pants" Chuckles the clown
-
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..
// 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(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(parent);
#ifdef LAMBDA
qDebug()<<"TRACE "<< __LINE__ ;
#endif
int index=0;
const QList actions=menu->actions();
for(const QAction *act : actions)
{
#ifdef LAMBDA
qDebug()<<"TRACEI suggest looking through all your code (there really is no "points" when something comes to an "action" especially when ALL of the code is not available) for "typedef". Then, assuming these errors are sallying forth from the mingw/gnu/etc compiler you're using, and have no code associated with them to differentiate one from the other, change any typedefs of the form: (this only an example, not the code you have) std::vector::size_type To std::vector::size_type size See if any errors go away.
-
I suggest looking through all your code (there really is no "points" when something comes to an "action" especially when ALL of the code is not available) for "typedef". Then, assuming these errors are sallying forth from the mingw/gnu/etc compiler you're using, and have no code associated with them to differentiate one from the other, change any typedefs of the form: (this only an example, not the code you have) std::vector::size_type To std::vector::size_type size See if any errors go away.
Thanks, the code is an example I found, so I am just starting to modify it for my use. I stopped when I received the error. I actually got more , but I just do not see how to fix the "action". The "problem" is - the original error "pointed " on "connect" and this error "points " on "action" Let me work on this...maybe I can actually clean up the whole "lambda".
-
Thanks, the code is an example I found, so I am just starting to modify it for my use. I stopped when I received the error. I actually got more , but I just do not see how to fix the "action". The "problem" is - the original error "pointed " on "connect" and this error "points " on "action" Let me work on this...maybe I can actually clean up the whole "lambda".
Here is modified , incomplete , code .
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(); // no parameters , all variables are class members , is that OK ?obj.connect(&subMenu\[index\],&QMenu::triggered,&subMenu\[index\],\[\](QAction\* action) {// lambda }// lambda );
#ifdef LAMBDA
text = "END TASK DEBUG LAMBDA... ";
text += Q_FUNC_INFO;
text += QString::number(__LINE__);
qDebug() << text;
#endifreturn 0;
}
Now I am getting this error
/mnt/A_BT_DEC10/BT__PROGRAMS/A_JAN11/A_BT_LIBRARY/terminal_Bluetooth/mainwindow_Bluetooth_copy.cpp:92: error: base of member reference is a function; perhaps you meant to call it with no arguments?
I am still lost... (I do not like lambda - too cryptic )
-
Here is modified , incomplete , code .
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(); // no parameters , all variables are class members , is that OK ?obj.connect(&subMenu\[index\],&QMenu::triggered,&subMenu\[index\],\[\](QAction\* action) {// lambda }// lambda );
#ifdef LAMBDA
text = "END TASK DEBUG LAMBDA... ";
text += Q_FUNC_INFO;
text += QString::number(__LINE__);
qDebug() << text;
#endifreturn 0;
}
Now I am getting this error
/mnt/A_BT_DEC10/BT__PROGRAMS/A_JAN11/A_BT_LIBRARY/terminal_Bluetooth/mainwindow_Bluetooth_copy.cpp:92: error: base of member reference is a function; perhaps you meant to call it with no arguments?
I am still lost... (I do not like lambda - too cryptic )
You are getting somewhere. Try this:
QObject obj; //if constructor doesn't require parameters there are no empty parenthesis
Salvatore Terress wrote:
(I do not like lambda - too cryptic )
Tough! :D
Mircea
-
Here is modified , incomplete , code .
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(); // no parameters , all variables are class members , is that OK ?obj.connect(&subMenu\[index\],&QMenu::triggered,&subMenu\[index\],\[\](QAction\* action) {// lambda }// lambda );
#ifdef LAMBDA
text = "END TASK DEBUG LAMBDA... ";
text += Q_FUNC_INFO;
text += QString::number(__LINE__);
qDebug() << text;
#endifreturn 0;
}
Now I am getting this error
/mnt/A_BT_DEC10/BT__PROGRAMS/A_JAN11/A_BT_LIBRARY/terminal_Bluetooth/mainwindow_Bluetooth_copy.cpp:92: error: base of member reference is a function; perhaps you meant to call it with no arguments?
I am still lost... (I do not like lambda - too cryptic )
Salvatore Terress wrote:
(I do not like lambda - too cryptic )
There's nothing that says you have to use a lambda. Sometimes, the capture variables are very useful, but if you'd rather write a normal function, the go ahead and do so. Sometimes a function object works best: [Function Objects in the C++ Standard Library | Microsoft Learn](https://learn.microsoft.com/en-us/cpp/standard-library/function-objects-in-the-stl?view=msvc-170)
"A little song, a little dance, a little seltzer down your pants" Chuckles the clown
-
Salvatore Terress wrote:
(I do not like lambda - too cryptic )
There's nothing that says you have to use a lambda. Sometimes, the capture variables are very useful, but if you'd rather write a normal function, the go ahead and do so. Sometimes a function object works best: [Function Objects in the C++ Standard Library | Microsoft Learn](https://learn.microsoft.com/en-us/cpp/standard-library/function-objects-in-the-stl?view=msvc-170)
"A little song, a little dance, a little seltzer down your pants" Chuckles the clown
I am using this code example to get more familiar with "connect". I am at 3rd attempt to write easy to understand way to process menu / submenu code. I had it working at one time, for one menu. Now I am adding more menu and now my submenus are "multiple selection" instead of single submenu. This code example seems to have that "fixed" , but now it is using lambda...