Unsolved How to connect signal and slot in different classes in Qt
-
This post is deleted! -
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."
-
You may have to adapt the connect statement to your needs, since it is based in the example above on a number of assumptions.
You need to post the relevant parts of mainwindow.h.
-
@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); }
-
Stupid question: did you also allocate memory for an instance of reader?
-
@koahnig Yes, reader *MyReader = new reader();
-
And you do the instance allocation prior to connect?
Probably you need to show more code and to tell us where exactly the error occurs when you step through the debugger.
What is your OS?
-
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.