Click here to Skip to main content
15,887,313 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to identify the "sender" of Qt "connect" function.

the
int i = RXobject->senderSignalIndex();

seems a good way to accomplish my task, but...

I get the "protected" member and do not know how to proceed...

Please ignore irrelevant code , this is "under construction"
and I am asking C++ question , nothing to do with Qt.




C++
void   MainWindow_Bluetooth::processMenu(int index_submenu, int index_mainmenu)
{
#ifdef LAMBDA
    text = "TASK DEBUG connect... "; //connect
    text += Q_FUNC_INFO;
    text += QString::number(__LINE__);
    // move index to class !!!
    text += " main loop index_main ";
    text += QString::number(index_mainmenu);
    text += " embeded loop  index_sub ";
    text += QString::number(index_submenu);
    text += " main loop class passed index ";
    text += QString::number(index);
    qDebug() << text;
#endif
    {// analyze indexes received block
        QString text;
        QObject *RXobject = sender();
        RXobject->dumpObjectInfo();
        QObjectList children = RXobject->children();
       //; text = RXobject->children().at(0);
        //QObjectList *RXChildren = RXobject->children();
        //QObject *RXparent = RXobject->parent();
        //QObject *TEST_parent = RXparent->parent();

        // protected member ???
int i = RXobject->senderSignalIndex();


//int SenderIndex = RXobject::​senderSignalIndex();

        //text = RXobject->dumpObjectInfo();

        text = Q_FUNC_INFO;
        qDebug() << text;







/mnt/A_BT_DEC10/BT__PROGRAMS/A_JAN11/A_BT_LIBRARY/terminal_Bluetooth/mainwindow_Bluetooth_copy.cpp:3890: error: 'senderSignalIndex' is a protected member of 'QObject'
mainwindow_Bluetooth_copy.cpp:3890:19: error: 'senderSignalIndex' is a protected member of 'QObject'
int i = RXobject->senderSignalIndex();
                  ^
/home/nov25-1/Qt/5.15.2/gcc_64/include/QtCore/qobject.h:435:9: note: can only access this member on an object of type 'MainWindow_Bluetooth'
    int senderSignalIndex() const;
        ^


What I have tried:

Ask Mrs Google to provide example of "sender(*) " usage... no luck
Posted
Updated 24-Jan-24 7:08am
v2

If I understand what you're trying to do, you don't "resolve" that method. Protected members of a class are only accessible from the class code itself or from inheritors of the class, which I think is QObject.

Since your code is neither, you cannot call that method. It's for internal use of the QObject class itself. That's why you can't find any information on it on the web.
 
Share this answer
 
Comments
Salvatore Terress 24-Jan-24 15:02pm    
I found this
QMetaMethod metaMethod = sender()->metaObject()->method(senderSignalIndex());
I really do not know HOW it works, but it manages to access senderSignalIndex , but the index returned does not make sense... so part of the problem is solved.. I will RTFM about QMetaMethod next...
KarstenK 25-Jan-24 4:41am    
he should get the source code from https://www.qt.io/download-open-source
Because QT is open source you can get the source code.
Read the documentation for details. Normally some installation and preparation. Pay attention that you need some compatible OS.
 
Share this answer
 
I guess you should replace
Quote:
int i = RXobject->senderSignalIndex();
with
int i = senderSignalIndex();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900