Signal Slot Qt5

Signal Slot Qt5 Average ratng: 5,0/5 9177 reviews
Hi
I have a Qt 'signal-slot connection'.
I want to test the class with the signal
The class with the slot is mocked/stubbed.
Now I would like to verify that when I emit signal, the slot is
called.
I wonder if it is possible to use gmock to verify this.
// class Tx contains the signal, which is protected so I inherit
// to get access to it
class Test : public ::testing::Test, public Tx
{ public:
MockRx *rx;
void SetUp()
{ rx = new MockRx;
rx->rxsignal(); // Just to see it compiles
rx->gmock_rxsignal(); // Compiles, gmock generated function
QObject::connect(this, SIGNAL(txsignal(), rx, SLOT(rxsignal()));
}
void TearDown() { delete rx; }
};
TEST_F(Test, Signal)
{
EXPECT_CALL(*rx, rxsignal()).Times(1).WillOnce(Return());
this->txsignal();
}
class MockRx : public QWidget
{ Q_OBJECT
public:
MOCK_METHOD0(rxsignal, void());
};
When running, I get the error:
QObject::connect: No such slot as RxMock::rxsignal()
If I remove Q_OBJECT in class MockRx, I get: No such slot as
QWidget::rxsignal()
I also tried to QObject::conntect(... SLOT(gmock_rxsignal()));
which gives No such slot as RxMock::rxsignal()
If I replace the MockRx class with a class Rx with rxsignal()
everything works.
I wonder why QObject::connect cannot find RxText::rxsignal() when
- it works if I replace with a regular class Rx instead of class
MockRx
- rx->rxsignal() can be called
Is gmock doing something under the hood that prevents this?
Hope someone can help, thanks a lot
Paul
Qt5 signal slot syntaxQt5 signal slot tutorialSignal Slot Qt5

Qt5 Signal Slot

Slot

Signal Slot Qt

Qt5插件使用信号槽机制通信 / Qt 5 plugin with signal-slots. Contribute to 3dBPoint/Qt5PluginSignalSlots development by creating an account on GitHub. Signal, Slot, Qt, Qt5 Quite a frequent problem when working with signals with slots in Qt5, according to my observations on the forum, is the connection of slots in the syntax on the pointers to signals having an overload of the signature. The same applies to slots that have an overload. Let's take a test class that has overloaded signals.