Description
Issue: Following the documentation for the subscribe method of a QGrpcCallReply generates a compiler error
Possible solution: Update the templates defined in qgrpccallreply.h at lines 21 and 31 to take a receiver of type
const typename QtPrivate::ContextTypeForFunctor<Func1, void>::ContextType *
instead of QObject *
To reproduce:
First, create any GRPC client with any rpc method. Also, create a MainWindow. Inside of the MainWindow's constructor, call the rpc method like this:
QGrpcCallReply *bla = client->Method(*new Empty()).get();
The following, taken from the Qt GRPC documentation here https://doc.qt.io/qt-6/qgrpccallreply.html works fine:
//Works fine QObject::connect(bla, &QGrpcCallReply::finished, this, std::forward<void(MainWindow::*)()>(&MainWindow::connCheckSuccessSlot));
However, the following, also taken directly from the documentation generates a compiler error:
//Compiler error bla->subscribe(this, &MainWindow::connCheckSuccessSlot);
The compiler cannot resolve the correct method on qgrpccallreply.h line 35. It should resolve
QObject::connect(const QtPrivate::FunctionPointer ::Object *sender, Func1 signal, const QtPrivate::ContextTypeForFunctor ::ContextType *context, Func2 &&slot, Qt::ConnectionType type = Qt::AutoConnection)
but because receiver is QObject* in the template definition this fails with an error:
/home/lewis/Qt/6.7.0/gcc_64/include/QtGrpc/qgrpccallreply.h:35:59: error: invalid conversion from 'QObject*' to 'const QtPrivate::ContextTypeForFunctor<void (MainWindow::*)(), void>::ContextType*' {aka 'const MainWindow*'} [-fpermissive]
Enabling -fpermissive as suggested does not enable the conversion.
If I edit the template definition in qgrpccallreply.h line 31 like this:
template<typename Func1> void subscribe(const QtPrivate::ContextTypeForFunctor<Func1, void>::ContextType *receiver, Func1 &&finishCallback, Qt::ConnectionType type = Qt::AutoConnection) { QObject::connect(this, &QGrpcCallReply::finished, receiver, std::forward<Func1>(finishCallback), type); }
The code compiles fine.
Attachments
For Gerrit Dashboard: QTBUG-124217 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
554606,4 | Forward the Receiver type to the connect call in QGrpcCallReply::subscribe | dev | qt/qtgrpc | Status: MERGED | +2 | 0 |