A
A
Alexander2015-07-04 15:12:48
Qt
Alexander, 2015-07-04 15:12:48

How to connect a signal with "unknown" arguments to a slot in Qt?

How can you connect an "unknown" signal to a slot that accepts all parameters - QVariant ?
There is such a function:

void createConnection(QWidget *sender, char *signal, zval *receiver, char *slot) {
  /*
   * тут я заношу в массив отправителя сигнала, 
   * сигнатуру сигнала, 
   * обработчика сигнала
   * и сигнатуру слота, чтобы потом обращаться к ним
   */
 
  // дальше мне нужно законнектить сигнал со слотом
  // сначала у меня было так:
  connect(sender, signal, this, SLOT(phpslot()));
}

char *signal - looks something like this: 1clicked() , char *slot - too. the phpslot()
function finds the required receiver from the list and calls the corresponding slot, but in this way I cannot pass parameters to the receiver'a slot , because the phpslot() function does not accept anything ... then I tried to rewrite the phpslot () function like this:
public slots:
    void phpslot(const QVariant &v0 = NULL,
                 const QVariant &v1 = NULL,
                 const QVariant &v2 = NULL,
                 const QVariant &v3 = NULL,
                 const QVariant &v4 = NULL,
                 const QVariant &v5 = NULL,
                 const QVariant &v6 = NULL,
                 const QVariant &v7 = NULL,
                 const QVariant &v8 = NULL,
                 const QVariant &v9 = NULL) {
             /* ... */
    }

and a function to create connections like this:
void createConnection(QWidget *sender, char *signal, zval *receiver, char *slot) {
  /*
   */
 
  QString sslot = QString(slot);
  QString phpqt_slot = "1phpslot" + sslot.mid(sslot.indexOf("("), sslot.indexOf(")")); // типа создаю сигнатуру функции php_slot()
  // например, если слот пришел таким: "1update(int, int, int)", то он тупо превратится в "1phpslot(int, int, int)"
 
  connect(sender, signal, this, php_slot);
}

Now when I try to legalize a signal with a slot, only signals are successfully processed without passing any parameters. Well, for example, the clicked() signal and the mySomeSlot() slot will create a "binding", but trying to bind the clicked(bool) signal to mySomeSlot(bool) will generate the following warning at runtime:
QObject::connect: No such slot ::phpslot(bool)
This option:
connect(sender, signal, this, SLOT(phpslot(QVariant,QVariant,QVariant,QVariant,QVariant,QVariant,QVariant,QVariant,QVariant,QVariant)));

does not create any bindings at all and gives the following warning:
QObject::connect: Incompatible sender/receiver arguments

Moreover, the warning will not change, even if instead of the entire heap of QVariants, only the required number of parameters, for example one, will be passed to phpslot (...) .
and this:
connect(sender, signal, this, &phpslot);
does not even compile with an error:
ошибка: no matching function for call to 'Phpqt5::connect(PQWidget*&, char*&, Phpqt5*, void (Phpqt5::*)(const QVariant&, const QVariant&, const QVariant&, const QVariant&, const QVariant&, const QVariant&, const QVariant&, const QVariant&, const QVariant&, const QVariant&))'
         connect(sender, signal, this, &phpslot);

how to create a signal-slot connection for such a case? =)
Ps Another idea was to simply get the list of passed arguments from the signal, and call the desired slot with these arguments, but I did not google how to do this.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vitaly, 2015-07-05
@vt4a2h

Look in the direction of the Qt meta system, in particular QMetaMethod (how to connect, how to get a list of parameters, etc.).
And of course, the main question: what problem are you trying to solve in this way? It might not be exactly what you need.)

J
Jacob E, 2015-07-06
@Zifix

I would suggest trying the new connect syntax , no parameters are required there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question