简体   繁体   中英

Qt signal not working when passing pointer to a struct

I have a Qt form that emits a signal; the signal passes a pointer to a structure which contains a load of data that the main window then sends out of my qextserialport.

This was working, but I have done something [unknown] and now when I connect the signal to a slot, unless I change it so that the singal does not pass anything, the connection to the signal will not work.

In mainwindow.cpp I have this:

void MainWindow::qt1245ValuesReceivedFromKeypad(char *dataPtr)
{

    bool connected;

    qt1245Window = new qt1245(this);
    connected = connect(qt1245Window,SIGNAL(sendMessageToKeypad(struct qt1245MessageStruct *qm)),this,SLOT(sendToQT1245(struct qt1245MessageStruct *qm)));
    qt1245Window->setupDataFromKeypad(dataPtr);
    qt1245Window->keyMapping(BinData);
    qt1245Window->keyDropDownChanged("DIM");       
 //   connected = connect(qt1245Window,SIGNAL(sendMessageToKeypad()),this,SLOT(sendToQT1245()));
    qt1245Window->exec();        
}

If I uncomment the second connect, and comment the first, and change the appropriate code, the connect works.

The structure is defined thus:

struct qt1245MessageStruct
{

    quint8 *dataPtr;
    quint8 length;
    quint8 keypadStartAddress;
    quint8 programType;

};

In qt1245.h I have this as part of the class declaration:

signals:
    void sendMessageToKeypad(struct qt1245MessageStruct *qm);

in qt1245.cpp. the signal is emitted as follows:

void qt1245::sendQT1245Message(qt1245MessageStruct *qm)
{

    emit sendMessageToKeypad(qm);

}

Can anyone shed any light on why connect returns false if I try to pass the pointer to the structure please? Also, is there away of making Qt give information as to why the connect fails, rather than just saying it has ?

If you need any more information, I will post it. I'm not sure at this juncture what would assist.

FWIW I'm on Linux, Qt Creator 4.9.0 based on Qt 5.12.2.

The parameters in the connect call are wrong.

connect(qt1245Window,
        SIGNAL(sendMessageToKeypad(struct qt1245MessageStruct*qm)),
        this,
        SLOT(sendToQT1245(struct qt1245MessageStruct *qm)));

The name of the parameter does not go into the SIGNAL and SLOT macros. The correct syntax is:

connect(qt1245Window,
        SIGNAL(sendMessageToKeypad(struct qt1245MessageStruct*)),
        this,
        SLOT(sendToQT1245(struct qt1245MessageStruct *)));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM