Problem with signal/slot from class
-
Hi there:
I have issues getting a signal/slot working from a class. Does this class need to be a thread to accept signal/slots?In the main app I connect like this:
mColorLib = new ColorLib(this); connect( mColorLib, &ColorLib::signalTellUser, this, &SpectraProof::slotTellUser, Qt::BlockingQueuedConnection );What I send from class:
emit signalTellUser(tr("Warning:"), tr("File format not supported yet."));My class header:
class ColorLib : public QObject { Q_OBJECT public: explicit ColorLib(QObject *parent = 0); signals: void signalTellUser(QString title, QString message); public: void open(QDir colorLibSubFolder); }; #endif // COLORLIB_H -
@ademmler said in Problem with signal/slot from class:
Qt::BlockingQueuedConnection
remove the last argument and check it, let it be decided based on the signalling and receiver object context.
Qt::BlockingQueuedConnection in this type of connection the signalling thread blocks until the slot returns. This connection must not be used if the receiver lives in the signalling thread, or else the application will deadlock. -
@ademmler said in Problem with signal/slot from class:
Qt::BlockingQueuedConnection
remove the last argument and check it, let it be decided based on the signalling and receiver object context.
Qt::BlockingQueuedConnection in this type of connection the signalling thread blocks until the slot returns. This connection must not be used if the receiver lives in the signalling thread, or else the application will deadlock.@nagesh thx for oyur response. the problem still exists .
connect( mColorLib, &ColorLib::signalTellUser, this, &SpectraProof::slotTellUser);
What is the best way to debug slots/signals?
The connect seems to be valid, because I do not get any complains while application launch. -
Hi there:
I have issues getting a signal/slot working from a class. Does this class need to be a thread to accept signal/slots?In the main app I connect like this:
mColorLib = new ColorLib(this); connect( mColorLib, &ColorLib::signalTellUser, this, &SpectraProof::slotTellUser, Qt::BlockingQueuedConnection );What I send from class:
emit signalTellUser(tr("Warning:"), tr("File format not supported yet."));My class header:
class ColorLib : public QObject { Q_OBJECT public: explicit ColorLib(QObject *parent = 0); signals: void signalTellUser(QString title, QString message); public: void open(QDir colorLibSubFolder); }; #endif // COLORLIB_H -
@Christian-Ehrlicher the class emits the signal and the slot is in the main app ...
I do the same with another class - same code lines and there it works ...
Hence I do not recall find any difference. -
@ademmler said in Problem with signal/slot from class:
the class emits the signal and the slot is in the main app ...
Which functions triggers the signal? Are you sure the correct instance is used? Simply add some debug output or use a debugger to see what instance you're using where.
-
@ademmler said in Problem with signal/slot from class:
the class emits the signal and the slot is in the main app ...
Which functions triggers the signal? Are you sure the correct instance is used? Simply add some debug output or use a debugger to see what instance you're using where.
@Christian-Ehrlicher I have the debug output at the correct spot.
Right above the emit signal statement. Also no warnings about a "wrong" connect object ...
It is really wired. My only idea ist that this class over takes an Object while the other (where it is working) over takes a Thread. Does it need to be a Thread?Not working:
ColorLib::ColorLib(QObject *parent) : QObject(parent) { }Working:
MyMeasure::MyMeasure(QObject *parent): QThread(parent) { } -
Please provide a minimal, compilable example. Your code snippets don't help. Please show at least where you do the connect and emit the signal to see if you really call the correct object.
-
Please provide a minimal, compilable example. Your code snippets don't help. Please show at least where you do the connect and emit the signal to see if you really call the correct object.
@Christian-Ehrlicher thx for this suggestion. I can't upload here in the forum.
-
@ademmler said in Problem with signal/slot from class:
I can't upload here in the forum.
When it's minimal I would say it's below 50 lines of code so you can paste them here.
-
@ademmler said in Problem with signal/slot from class:
I can't upload here in the forum.
When it's minimal I would say it's below 50 lines of code so you can paste them here.
@Christian-Ehrlicher ok - that will take time - and of course in a minimal it is working corecctly. This we have tested already in another thread a year ago.
In the same project - slot/signal works if the class is derived with QThread and it does not if it misses QThread. Does this make a difference?