connecting signals and slots from different namespaces
Hello,
I have just solved a weird problem connecting signals and slots from different namespaces, but I want to be sure I am not complicating matters. I have the following class:
Code:
namespace MyLibrary
{
class Data {
};
class Emitter {
signals:
void newData(const Data& d);
};
}
Then, in MyApplication, I'm trying to connect to the "newData" signal as follows:
Code:
namespace MyApplication {
...
connect(emitter, SIGNAL(newData(const MyLibrary::Data&)), this, SLOT(onNewData(const MyLibrary::Data&)));
...
}
but this does not work. To make it work, I needed to change the Emitter class as follows:
Code:
class Emitter {
signals:
void newData(const MyLibrary::Data& d); // added namespace specifier: completely useless as far as C++ is concerned, I believe
};
Is this the standard way to fix the problem? Am I missing something?
Thank you
Re: connecting signals and slots from different namespaces
Signal and slot names are compared character by character thus tricks like the one you used are required. Of course you can get away from this with the "using" keyword but your method is also fine.
Re: connecting signals and slots from different namespaces
I think my problem is similar.
I've got a class and inside a struct definition. The class also emit a signal with this structure.
Code:
class MatrixModule
: public QObject{
Q_OBJECT
public:
struct DataReceived
{
int packetID; //!< Packet ID
int linkQualityIndicator; //!< Link Quality Indicator gives feedback to the strength of the received packet
// Host/Application
Address source; //!< Source Transceiver Address
Address destination; //!< Destination Transceiver Address
QByteArray message;
//!< Message received over the RF link };
signals:
void dataReceived(const DataReceived);
}
Here the code where the signal is emitted
Code:
DataReceived packetReceived;
[...]
emit dataReceived(packetReceived) ;
The error:
Code:
error
: no match
for call to ‘
(const QByteArray)(MatrixModule
::DataReceived&)’
Where is the problem?
In my code there is also an another class with he signal
Code:
void dataByteReceived
(const QByteArray &);
//!< Data Available from the QextSerialPort
that is connected with the method that I've reported upper with the emission of the second signal after a data processing of the data provided by the serial port.
Re: connecting signals and slots from different namespaces
can you post the code connecting signals and slots?
Re: connecting signals and slots from different namespaces
Actualy the signal dataReceived(const DataReceived); is connected to nothing.
I only connected the dataByteReceived(const QByteArray &) to the slot the parsering the data provided by the serial port and emmited the first signal in this way
Code:
connect(d_receiveThread,
SIGNAL(dataByteReceived
(const QByteArray &)),
this,
SLOT(processDataReceived
(const QByteArray &)));
The error is associated at the line where emits my signal with my structure data.
Re: connecting signals and slots from different namespaces
I'm puzzled too... the error seems unrelated to the emit :confused:
1 Attachment(s)
Re: connecting signals and slots from different namespaces
If I comment only the line where I emit the signal, I've got no compile error.
Anyway I attach all my source code.
I don't know what to do :crying:
Re: connecting signals and slots from different namespaces
I try to change the signal with a very simple one
and I emit this whit this code
Code:
emit dataReceived(prova);
I can use this in my ReadingThread but in the MatrixModule I've got this error:
error: no match for call to ‘(const QByteArray) (const QByteArray&)’
Where is the real problem???
Re: connecting signals and slots from different namespaces
I fix!
In the slot where I emit the signal dataReceived(..) there was a QByteArray dataReceived.