0

It looks like the question is asked in the subj.

Here is an example:

class Sender : public QObject
{
  signals:
    sgSend(const QString&) const;
};

class Receiver : public QObject
{
  public slots:
    slReceive(const QString& value)
    { qDebug() << value; }
};

And if I connect them with the following line:

connect(sender, SIGNAL(sgSend(const QString&)), receiver, SLOT(slReceive(const QString&)));

my project is being built successfully, but it looks like the connection is not being established. I feel that I need to specify in some a way that the sgSend method is qualified with const, but I am not sure how to do this.

I think, if I'll use the new syntax of the connect, it will work. But for certain reasons, I cannot use it.

Serge Roussak
  • 1,731
  • 1
  • 14
  • 28
  • 1
    Off topic but... why can't you use the new Qt5 signal/slot syntax? – G.M. Jul 08 '20 at 11:07
  • Not really a duplicate but maybe of help: [SO: Argument type for Qt signal and slot, does const reference qualifiers matters?](https://stackoverflow.com/q/1935147/7478597) – Scheff's Cat Jul 08 '20 at 11:15
  • @G.M., because (a) my sender and receiver are in different modules (DLLs) and (b) my modules are being loaded manually (there is no DLL dependencies among projects >> linker does not "see" slots from another project >> errors during build). – Serge Roussak Jul 08 '20 at 11:17

1 Answers1

0

It seems, the issue was not in the incorrect signal signature. Actually, I specified incorrectly the receiver parameter in the connect call.

In any way, if someone will reach this page in the future, I found that the const qualified signal should be mentioned as if it is not:

connect(sender, SIGNAL(sgSend(const QString&)), receiver, SLOT(slReceive(const QString&)));

I.e., it doesn't matter whether the signal is declared as const or not -- the same (if we are talking about pre-5 Qt) syntax should be used.

Serge Roussak
  • 1,731
  • 1
  • 14
  • 28