How to connect signal and slot in different classes in Qt
-
Did you checkout already signal-slot page ?
Basically you need pointers of both classes for use in connect statement. Since your slot
private slots: void SlotDisplayProgress(QString sActivity_i, int nProgressPercentage_i);
you can only connect from a routine in MainWidnow (e.g. the ctor).
So if you have in MainWindow something like:
reader *MyReader;
you can have for instance in ctor
connect ( MyReader, &reader::SetProgress, this, &mainwindow::SlotDisplayProgress );
-
@koahnig said in How to connect signal and slot in different classes in Qt:
connect ( MyReader, &reader::SetProgress, this, &mainwindow::SlotDisplayProgress );
I am getting an exception after apply connect "Exception thrown at 0x00007FFE23CA063A (Qt5Cored.dll) in RadSpaEngine.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF."
-
@koahnig I tried debugging and everything works correctly till the emit part. However, the slot is never executed. Any help is useful to me.
class mainwindow : public QMainWindow { Q_OBJECT reader *MyReader; private slots: void SlotDisplayProgress(QString sActivity_i, int nProgressPercentage_i); }
-
Hi,
@amarism said in How to connect signal and slot in different classes in Qt:
@koahnig Yes, reader *MyReader = new reader();
Any chance that this line is in your constructor ? If so, you are shadowing your member variable and not allocating anything to it.
-
@amarism said in How to connect signal and slot in different classes in Qt:
location 0xFFFFFFFFFFFFFFFF.
That's definitely a pointer error that doesn't have anything directly to do with signals or slots. What you really want to do is read the documentation on the QtCreator debugger so you can understand which variable has that invalid address 0xFFFFFFFFFFFFFFFF, and rework your logic. That sort of error message indicates that any function you tried to use on or in that object would explode badly, not just the connect().
Because you are focused on the signals/slots that you are trying to accomplish, you may be "missing the forest for the trees" in trying to find a solution.